Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for negative millisecond offset #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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?

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
2 participants