Skip to content

Commit

Permalink
Zip: force Disk Start Number to -1 in a Zip64 Central Directory Entry
Browse files Browse the repository at this point in the history
When using Zip64 in the Central Directory Entry, the Extra block always
includes the Disk Start Number (regardless of whether is it needed or not.)

Clause 4.5.3 of the PKWare spec clearly states that it MUST only appear in
the Extra block when the corresponding field in the CDE (or LDE) was set to
-1 (0xFFFF in the case of the Disk Start Number.)

Some tools (such as 7-Zip) show warnings in this case, but often work as
expected. Others (such as older versions of System.IO.Compression) follow
the spec more stringently and will refuse to use the values from the Zip64
Extra block when the related values do not match their expectation.

Fixes haf#260
  • Loading branch information
BhaaLseN committed Aug 5, 2022
1 parent 4ab8c0e commit 3a392a6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Zip.Shared/ZipEntry.Write.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,24 @@ this file starts
}
else
{
// If reading a segmneted archive and saving to a regular archive,
// ZipEntry._diskNumber will be non-zero but it should be saved as
// zero.
bytes[i++] = 0;
bytes[i++] = 0;
if (_presumeZip64)
{
// the Extra block for Zip64 always includes the 'Disk Start',
// so we MUST also set them to -1 (0xFFFF) and direct readers
// to the Zip64 field. Not doing this would display warnings
// in 7-Zip and fail to extract with older versions of
// System.IO.Compression. (GitHub issue #260)
bytes[i++] = 0xFF;
bytes[i++] = 0xFF;
}
else
{
// If reading a segmneted archive and saving to a regular archive,
// ZipEntry._diskNumber will be non-zero but it should be saved as
// zero.
bytes[i++] = 0;
bytes[i++] = 0;
}
}

// internal file attrs
Expand Down

0 comments on commit 3a392a6

Please sign in to comment.