System.IO.Packaging: Avoid setting the general purpose bitflag due to enforced UTF8 encoding on ZipArchive creation #87883
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.
Fixes #87658
The ZipArchive constructor is being called by ZipPackage with the
entryNameEncoding
argument set toEncoding.UTF8
. This is not needed by default, particularly because it's not respecting the Office XML standard which does not expect the general purpose bit flag 11 to be set. The entry name can still be stored using UTF8 if the archive encoding is unset or null, and the general purpose bit flag for entryname and comment encoding can still be changed later if the caller changes the entry name or the comment to a string with an encoding other than ASCII.This change is relatively safe to make since ZipArchive is capable of handling archives without specifying a particular encoding.
This was verified with a manual test with @ericstj in a video call: we confirmed with reflection that the
_generalPurposeBitFlag
was now left unchanged by default, and an inspection of the generated file using a hex editor showed that the relevant bytes were unset.We will add tests as a followup of the original issue. #87882