"invalid CEN header (bad signature)" when extracting a 4GB+ file from a zip archive using Java 8 jar command

vallismortis :

I have a zip file that contains 5 files. Four of the files are small (a few kB), but one file is larger than 4GB. I'm aware of JDK-4681995, which added large file support (64-bit zip support) to Java starting in Java 7. I'm using 64 bit Java 8 on Windows 8.1:

C:\Users\user\Desktop>java -version
java version "1.8.0_212"
Java(TM) SE Runtime Environment (build 1.8.0_212-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.212-b10, mixed mode)

The zip file size is as follows:

07/07/2019  10:18 AM       503,966,751 snapshot-20190707.zip

The contents of the zip file are:

07/07/2019  09:53 AM                67 database.sha1
07/07/2019  09:51 AM     4,508,840,068 database.sql
07/07/2019  09:53 AM                74 database_schema.sha1
07/07/2019  09:51 AM            36,386 database_schema.sql
07/07/2019  09:51 AM            45,280 backup.log

If I try to extract the 4GB file, I encounter an exception that looks exactly like the Java 7 exception for 64-bit zip files:

C:\Users\user\Desktop>jar xvf snapshot-20190707.zip database.sql
java.util.zip.ZipException: invalid CEN header (bad signature)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:225)
        at java.util.zip.ZipFile.<init>(ZipFile.java:155)
        at java.util.zip.ZipFile.<init>(ZipFile.java:126)
        at sun.tools.jar.Main.extract(Main.java:1004)
        at sun.tools.jar.Main.run(Main.java:305)
        at sun.tools.jar.Main.main(Main.java:1288)

Is there any way to extract a 4GB+ file from a 64-bit zip archive using the Java 8+ jar command?

vallismortis :

This exception is caused by bug JDK-8223811 in Java 8, which is triggered by the -f flag. The submitter re-created the problem using:

jar xvf archive.zip *

From a comment on the bug report (May 19, 2019):

This is only reproducible on JDK 8 versions. It is fixed in JDK 9 and above and is not an issue in the latest JDK 11, 12 or 13.

The workaround for Java 8 is to avoid specifying an individual file when using the -f flag, and to simply extract all files in the archive:

This version of the command successfully extracts all files without any problems:

C:\Users\user\Desktop>jar xvf snapshot-20190707.zip
 inflated: backup.log
 inflated: database_schema.sha1
 inflated: database_schema.sql
extracted: database.sha1
 inflated: database.sql

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=311229&siteId=1