@@ -263,4 +263,36 @@ private ZipArchiver getZipArchiver(File destFile) {
263
263
zipArchiver .setDestFile (destFile );
264
264
return zipArchiver ;
265
265
}
266
+
267
+ @ Test
268
+ void testZipWithNegativeModificationTime () throws Exception {
269
+ // Create a zip file with an entry that has -1 modification time
270
+ File zipFile = new File ("target/output/zip-with-negative-time.zip" );
271
+ zipFile .getParentFile ().mkdirs ();
272
+
273
+ // Create a simple zip file using Apache Commons Compress
274
+ try (org .apache .commons .compress .archivers .zip .ZipArchiveOutputStream zos =
275
+ new org .apache .commons .compress .archivers .zip .ZipArchiveOutputStream (zipFile )) {
276
+ org .apache .commons .compress .archivers .zip .ZipArchiveEntry entry =
277
+ new org .apache .commons .compress .archivers .zip .ZipArchiveEntry ("test-file.txt" );
278
+ // Set modification time to -1 to simulate unspecified modification time
279
+ entry .setTime (-1 );
280
+ zos .putArchiveEntry (entry );
281
+ zos .write ("Test content" .getBytes ());
282
+ zos .closeArchiveEntry ();
283
+ }
284
+
285
+ // Now try to extract it - this should not throw an IllegalArgumentException
286
+ File outputDirectory = new File ("target/output/zip-negative-time-extract" );
287
+ FileUtils .deleteDirectory (outputDirectory );
288
+ outputDirectory .mkdirs ();
289
+
290
+ ZipUnArchiver zu = getZipUnArchiver (zipFile );
291
+ zu .extract ("" , outputDirectory );
292
+
293
+ // Verify the file was extracted
294
+ File extractedFile = new File (outputDirectory , "test-file.txt" );
295
+ assertTrue (extractedFile .exists ());
296
+ assertEquals ("Test content" , new String (java .nio .file .Files .readAllBytes (extractedFile .toPath ())));
297
+ }
266
298
}
0 commit comments