Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public InputStream getContents() throws IOException {
@Override
public long getLastModified() {
final long l = zipEntry.getTime();
return l == 0 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l;
return l <= 0 ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : l;
}

@Override
Expand Down Expand Up @@ -174,12 +174,16 @@ protected void execute(final String path, final File outputDirectory) throws Arc
.setInputStream(in)
.setMaxCount(remainingSpace + 1)
.get();
long time = ze.getTime();
if (time <= 0) {
time = PlexusIoResource.UNKNOWN_MODIFICATION_DATE;
}
extractFile(
getSourceFile(),
outputDirectory,
bis,
ze.getName(),
new Date(ze.getTime()),
new Date(time),
ze.isDirectory(),
ze.getUnixMode() != 0 ? ze.getUnixMode() : null,
resolveSymlink(zipFile, ze),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,36 @@ private ZipArchiver getZipArchiver(File destFile) {
zipArchiver.setDestFile(destFile);
return zipArchiver;
}

@Test
void testZipWithNegativeModificationTime() throws Exception {
// Create a zip file with an entry that has -1 modification time
File zipFile = new File("target/output/zip-with-negative-time.zip");
zipFile.getParentFile().mkdirs();

// Create a simple zip file using Apache Commons Compress
try (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream zos =
new org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream(zipFile)) {
org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry =
new org.apache.commons.compress.archivers.zip.ZipArchiveEntry("test-file.txt");
// Set modification time to -1 to simulate unspecified modification time
entry.setTime(-1);
zos.putArchiveEntry(entry);
zos.write("Test content".getBytes());
zos.closeArchiveEntry();
}

// Now try to extract it - this should not throw an IllegalArgumentException
File outputDirectory = new File("target/output/zip-negative-time-extract");
FileUtils.deleteDirectory(outputDirectory);
outputDirectory.mkdirs();

ZipUnArchiver zu = getZipUnArchiver(zipFile);
zu.extract("", outputDirectory);

// Verify the file was extracted
File extractedFile = new File(outputDirectory, "test-file.txt");
assertTrue(extractedFile.exists());
assertEquals("Test content", new String(java.nio.file.Files.readAllBytes(extractedFile.toPath())));
}
}
Loading