Fix AbstractZipUnArchiver handling of zip entries with unspecified modification time #393
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
According to the ZIP specification,
ZipEntry.getTime()
can legally return-1
to indicate that the modification time is not specified. However,AbstractZipUnArchiver
was passing this value directly tonew Date(-1)
and eventually toFile.setLastModified(-1)
, which throwsIllegalArgumentException: Negative time
.This caused extraction failures when attempting to unzip JAR files with entries that do not have a modification time set:
Solution
Added checks for
-1
modification time (in addition to the existing check for0
) in two locations:ZipEntryFileInfo.getLastModified()
: Now returnsPlexusIoResource.UNKNOWN_MODIFICATION_DATE
(which is0
) whenzipEntry.getTime()
returns either-1
or0
AbstractZipUnArchiver.execute()
: Sanitizes the modification time before creating theDate
object by checking if it's-1
or0
, and replacing it withUNKNOWN_MODIFICATION_DATE
This ensures that
File.setLastModified()
is never called with a negative value, while properly handling zip entries with unspecified modification times according to the ZIP specification.Testing
Added
testZipWithNegativeModificationTime()
which:-1
modification time using Apache Commons CompressZipUnArchiver
All existing tests continue to pass.
Fixes #262
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.