mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
Invalid EndOfCentralDirectory Record generated for Zip64 archive with over 65,535 files in ZipWriter #607
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DannyBoyk on GitHub (Dec 22, 2023).
Discovered today that Zip64 files generated by the ZipWriter with over 65,535 files generates an invalid EndOfCentralDirectory record. When it goes to write the
Number of central directory records on this disk (or 0xffff for ZIP64)andTotal number of central directory records (or 0xffff for ZIP64)fields (see https://en.wikipedia.org/wiki/ZIP_(file_format)#End_of_central_directory_record_(EOCD)), it does not write 0xffff when the number of files exceeds ushort.MaxValue.This line:
https://github.com/adamhathcock/sharpcompress/blob/master/src/SharpCompress/Writers/Zip/ZipWriter.cs#L307
Needs to be changed to:
BinaryPrimitives.WriteUInt16LittleEndian(intBuf, (ushort)(entries.Count < 0xFFFF ? entries.Count : 0xFFFF));As is, 7zip complains of a "Header error" for the EOCD record as written. And some other zip utilities refuse to process the zip with an error.
@adamhathcock commented on GitHub (Dec 22, 2023):
Do you mind making that a PR? Thanks!
@DannyBoyk commented on GitHub (Dec 22, 2023):
PR created. It's not 100% clear to me what the build failures on GitHub are about. It compiles fine and passes all tests on my Windows machine. Just a one line change.
@DannyBoyk commented on GitHub (Dec 22, 2023):
I see that it was some formatting thing in the build project, which I typically don't use. Can those rules not be enforced with code style rules? Anyway, build passing now.
@adamhathcock commented on GitHub (Dec 27, 2023):
It's enforced and correct with a dotnet tool. Thanks!