gildas-lormeau / zip.js

JavaScript library to zip and unzip files supporting multi-core compression, compression streams, zip64, split files and encryption.
https://gildas-lormeau.github.io/zip.js
BSD 3-Clause "New" or "Revised" License
3.38k stars 510 forks source link

Broken zip file: ZipWriter with options zip64 and level #409

Closed mzghoba closed 1 year ago

mzghoba commented 1 year ago

Unable to unzip the archive with few files and empty folders. ZipWriter should have zip64 and level options

async function getZipFileBlob() {
   const zipWriter = new ZipWriter(new BlobWriter(), {  zip64: true,  level: 1});

    await zipWriter.add("hello.txt", new TextReader("Hello world!"));
    await zipWriter.add("README.md", new HttpReader(README_URL));
    await zipWriter.add("/test", null, {directory: true });

  return zipWriter.close();
}

Result

image
gildas-lormeau commented 1 year ago

Does the Archive Utility support files using zip64?

mzghoba commented 1 year ago

Yes, I tried macOS archive utility, Keka app, and ditto CLI. The same error. But it works fine for zip64 without empty folders

gildas-lormeau commented 1 year ago

I did the same test, see https://plnkr.co/edit/qFaB9prJCyYSiVjv?open=lib%2Fscript.js&preview. I can extract the file with 7-zip, WinZip, and natively with the File Explorer on Windows 11 without any warning. From my point of view, it's a bug on macOS because directories have nothing particular with zip64 enabled. Anyway, you should not force zip64 to true unless you know what you're doing. zip.js can detect when to set to it true automatically.

gildas-lormeau commented 1 year ago

Actually, there might be something wrong. 7z confirms the entry is not detected as written in zip64, see Characteristics Volume index and Offset of the second entry.

7z l hello.zip -slt    

7-Zip [64] 17.05 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.05 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs LE)

Scanning the drive for archives:
1 file, 1191 bytes (2 KiB)

Listing archive: hello(19).zip

--
Path = hello(19).zip
Type = zip
Physical Size = 1191
64-bit = +
Characteristics = Zip64

----------
Path = lorem.txt
Folder = -
Size = 1162
Packed Size = 629
Modified = 2023-04-13 02:23:34
Created = 2023-04-13 02:23:34
Accessed = 2023-04-13 02:23:34
Attributes = 
Encrypted = -
Comment = 
CRC = 869415C8
Method = Deflate
Characteristics = Zip64 UT NTFS : Descriptor UTF8
Host OS = FAT
Version = 45
Volume Index = 0
Offset = 0

Path = test
Folder = +
Size = 0
Packed Size = 0
Modified = 2023-04-13 02:23:34
Created = 2023-04-13 02:23:34
Accessed = 2023-04-13 02:23:34
Attributes = D
Encrypted = -
Comment = 
CRC = 
Method = Store
Characteristics = 0x0 0x0 0x0 0x0 0x0 0x2DD 0x0 0x0 UT NTFS : Descriptor UTF8
Host OS = FAT
Version = 45
Volume Index = 65535
Offset = 4294967295
gildas-lormeau commented 1 year ago

Thank you for the report. The bug is fixed in the version 2.7.2. The generated zip file is now valid on https://plnkr.co/edit/qFaB9prJCyYSiVjv?open=lib%2Fscript.js&preview.

gildas-lormeau commented 1 year ago

For the record, 7z now displays the following result.

7z l hello.zip -slt

7-Zip [64] 17.05 : Copyright (c) 1999-2021 Igor Pavlov : 2017-08-28
p7zip Version 17.05 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs LE)

Scanning the drive for archives:
1 file, 1191 bytes (2 KiB)

Listing archive: hello.zip

--
Path = hello.zip
Type = zip
Physical Size = 1191
64-bit = +
Characteristics = Zip64

----------
Path = lorem.txt
Folder = -
Size = 1162
Packed Size = 629
Modified = 2023-04-13 02:54:07
Created = 2023-04-13 02:54:07
Accessed = 2023-04-13 02:54:07
Attributes = 
Encrypted = -
Comment = 
CRC = 869415C8
Method = Deflate
Characteristics = Zip64 UT NTFS : Descriptor UTF8
Host OS = FAT
Version = 45
Volume Index = 0
Offset = 0

Path = test
Folder = +
Size = 0
Packed Size = 0
Modified = 2023-04-13 02:54:07
Created = 2023-04-13 02:54:07
Accessed = 2023-04-13 02:54:07
Attributes = D
Encrypted = -
Comment = 
CRC = 
Method = Store
Characteristics = Zip64 UT NTFS : Descriptor UTF8
Host OS = FAT
Version = 45
Volume Index = 0
Offset = 733

The Characteristics, Volume index and Offset values of the second entry are now correct.

mzghoba commented 1 year ago

Thank you!

gildas-lormeau commented 1 year ago

You're welcome.