This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Repository navigation
Fix local zip entry header for large files - #36027
Merged
Merged
Conversation
When opened for Write ZipArchiveEntry needs to write the local header information to the archive stream upon the first call to write since the compressed content comes after that and we write directly to the backing stream rather than buffering in memory. By default header information only accommodates 32-bit sizes since this is much more likely and saves space in archives with lots of files and at the first write we don’t know how big the entry is going to be. Once the entry is disposed we know the final length and may find it cannot be represented in 32-bit fields. It can’t insert the extra bytes it would need in the header region since it’s already written the compressed data and streams/files don’t have insertion operations, so instead it sets a bit that says the entry's size information is in a descriptor at the end of the entry. The entry was setting the bit that indicated the descriptor existed but didn't set the version in the header to ZIP64 to indicate wether that descriptor had 64-bit fields. Additionally we were writing the central-directory header for the file with a version of ZIP64 so our local header and central header didn't match. May ZIP implementations were OK with this, but not all. Specifically WindowsBase.dll's implementation of the System.IO.Packaging APIs has a ZipArchive that insists the local header version must be ZIP64 to have a 64-bit descriptor. Moreover it also insists that the local-header version must match the central header version. To ensure zips created with .NETCore's System.IO.Packaging APIs work with desktop we should set this version field in the local header.
stephentoub
approved these changes
Mar 14, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When opened for Write ZipArchiveEntry needs to write the local header
information to the archive stream upon the first call to write since the
compressed content comes after that and we write directly to the backing stream
rather than buffering in memory.
By default header information only accommodates 32-bit sizes since this is much
more likely and saves space in archives with lots of files and at the first
write we don’t know how big the entry is going to be.
Once the entry is disposed we know the final length and may find it cannot be
represented in 32-bit fields. It can’t insert the extra bytes it would need
in the header region since it’s already written the compressed data and
streams/files don’t have insertion operations, so instead it sets a bit that
says the entry's size information is in a descriptor at the end of the entry.
The entry was setting the bit that indicated the descriptor existed but didn't
set the version in the header to ZIP64 to indicate wether that descriptor had
64-bit fields. Additionally we were writing the central-directory header for
the file with a version of ZIP64 so our local header and central header didn't
match.
Many ZIP implementations were OK with this, but not all. Specifically
WindowsBase.dll's implementation of the System.IO.Packaging APIs has a
ZipArchive that insists the local header version must be ZIP64 to have a
64-bit descriptor. Moreover it also insists that the local-header version must
match the central header version.
To ensure zips created with .NETCore's System.IO.Packaging APIs work with
desktop we should set this version field in the local header.
There's not a great way to test this in CI since the scenario is produce a zip
with file over 4GB on .NETCore and read it on desktop and we don't have
test scenarios that cross frameworks like that. We do cover this codepath
in the System.IO.Packaging outerloop test I added recently. Feel free to
chime in if you have any suggestions here.
Fixes #36013
/cc @pensivebrian