You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importjava.io.ByteArrayInputStream;
importjava.nio.file.Files;
importjava.nio.file.Paths;
importjava.util.Arrays;
importjava.util.List;
importnet.lingala.zip4j.ZipFile;
importnet.lingala.zip4j.model.FileHeader;
importnet.lingala.zip4j.model.ZipParameters;
importnet.lingala.zip4j.model.enums.CompressionLevel;
publicclassZipTest {
publicstaticvoidmain(String[] args) throwsException {
StringzipFileName = "big-file.zip";
generateTestFile(zipFileName);
addComment(zipFileName);
// net.lingala.zip4j.exception.ZipException: invalid signature for zip64 end of central directory recordreadZipFile(zipFileName);
}
privatestaticvoidgenerateTestFile(StringfileName) throwsException {
Files.deleteIfExists(Paths.get(fileName));
byte[] data = newbyte[1024 * 1024 * 1024];
Arrays.fill(data, (byte) 0);
ZipParameterscommonParams = newZipParameters();
commonParams.setCompressionLevel(CompressionLevel.NO_COMPRESSION);
try (ZipFilezipFile = newZipFile(fileName)) {
for (inti = 0; i < 5; i++) {
ZipParametersentryParam = newZipParameters(commonParams);
entryParam.setFileNameInZip("file-" + i + ".dat");
ByteArrayInputStreaminputStream = newByteArrayInputStream(data);
zipFile.addStream(inputStream, entryParam);
}
}
}
privatestaticvoidaddComment(StringfileName) throwsException {
try (ZipFilezipFile = newZipFile(fileName)) {
zipFile.setComment("comment");
}
}
privatestaticvoidreadZipFile(StringfileName) throwsException {
try (ZipFilezipFile = newZipFile(fileName)) {
// net.lingala.zip4j.exception.ZipException: invalid signature for zip64 end of central directory recordList<FileHeader> fileHeaders = zipFile.getFileHeaders();
for (FileHeaderfileHeader : fileHeaders) {
System.out.println(fileHeader.getFileName());
}
}
}
}
I checked the generated files using the command unzip -t big-file.zip and the output was as follows.
Archive: big-file.zip
comment
error: End-of-centdir-64 signature not where expected (prepended bytes?)
(attempting to process anyway)
warning [big-file.zip]: 1074561330 extra bytes at beginning or within zipfile
(attempting to process anyway)
file #1: bad zipfile offset (local header sig): 1074561330
(attempting to re-compensate)
testing: file-0.dat OK
testing: file-1.dat OK
testing: file-2.dat OK
testing: file-3.dat OK
testing: file-4.dat OK
At least one error was detected in big-file.zip.
The output of command zip -FF big-file.zip --out big-file-fix.zip was as follows.
Fix archive (-FF) - salvage what can
Found end record (EOCDR) - says expect single disk archive
Found archive comment
Scanning for entries...
copying: file-0.dat (1073905669 bytes)
copying: file-1.dat (1073905669 bytes)
copying: file-2.dat (1073905669 bytes)
copying: file-3.dat (1073905669 bytes)
copying: file-4.dat (1073905669 bytes)
Central Directory found...
Zip64 EOCDR found ( 1 5369528937)...
Zip64 EOCDL found ( 1 5369528993)...
EOCDR found ( 1 5369529013)...
The text was updated successfully, but these errors were encountered:
The following code can reproduce the exception.
I checked the generated files using the command
unzip -t big-file.zip
and the output was as follows.The output of command
zip -FF big-file.zip --out big-file-fix.zip
was as follows.The text was updated successfully, but these errors were encountered: