Fix AbstractZipUnArchiver handling of zip entries with unspecified modification time#393
Merged
slachiewicz merged 1 commit intomasterfrom Oct 8, 2025
Conversation
Copilot
AI
changed the title
[WIP] AbstractZipUnArchiver does not check for unspecified modification time
Fix AbstractZipUnArchiver handling of zip entries with unspecified modification time
Oct 5, 2025
slachiewicz
approved these changes
Oct 5, 2025
gnodet
reviewed
Oct 8, 2025
gnodet
reviewed
Oct 8, 2025
gnodet
reviewed
Oct 8, 2025
gnodet
requested changes
Oct 8, 2025
Member
gnodet
left a comment
There was a problem hiding this comment.
I think checking for <= 0 is easier.
gnodet
approved these changes
Oct 8, 2025
7d46ae4 to
1008193
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-1to indicate that the modification time is not specified. However,AbstractZipUnArchiverwas 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
-1modification time (in addition to the existing check for0) in two locations:ZipEntryFileInfo.getLastModified(): Now returnsPlexusIoResource.UNKNOWN_MODIFICATION_DATE(which is0) whenzipEntry.getTime()returns either-1or0AbstractZipUnArchiver.execute(): Sanitizes the modification time before creating theDateobject by checking if it's-1or0, and replacing it withUNKNOWN_MODIFICATION_DATEThis 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:-1modification time using Apache Commons CompressZipUnArchiverAll 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.