Skip to content

Conversation

rovarga
Copy link

@rovarga rovarga commented Apr 22, 2021

File.setLastModified() does not allow negative values, but those
can be present in Date. One such source is ZipEntry.getTime(), which
returns -1 to indicate a non-applicable time. Fixes #170.

Signed-off-by: Robert Varga [email protected]

File.setLastModified() does not allow negative values, but those
can be present in Date. One such source is ZipEntry.getTime(), which
returns -1 to indicate a non-applicable time.

Signed-off-by: Robert Varga <[email protected]>
@plamentotev plamentotev added the bug label May 1, 2021
@plamentotev plamentotev added this to the plexus-archiver-4.2.6 milestone May 1, 2021
final long millis = entryDate.getTime();
if ( millis >= 0 )
{
targetFileName.setLastModified( millis );
Copy link
Member

@plamentotev plamentotev May 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find setLastModified behavior strange because lastModified works perfectly fine with negative values (dates before 1970-01-01). We can use Files.setLastModifiedTime, which works with negative values[1], and use null for missing date. Some archives, such as tar, support negative values so it should be up to the specific UnArchiver implementation to decide if the date is known or not.

[1] Whether the underlying file system supports it is different question. Unfortunately the behavior is unspecified if the date is out of range for the file system. Maybe we can just catch the exception so failure to set the date does not fail the file extraction?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look related to #393

@slachiewicz slachiewicz requested a review from Copilot October 5, 2025 13:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a validation check to prevent passing negative millisecond values to File.setLastModified(). The change addresses an issue where ZipEntry.getTime() can return -1 to indicate a non-applicable time, which would cause problems when passed directly to setLastModified().

  • Added millisecond value extraction and validation before calling setLastModified()
  • Only calls setLastModified() when the timestamp is non-negative

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AbstractZipUnArchiver does not check for unspecified modification time

3 participants