Fix length calculation when adding extended ascii filenames - #32
Merged
Merged
Conversation
pR0Ps
force-pushed
the
bugfix/length-non-asci-names
branch
from
August 20, 2026 03:29
e496c79 to
8814cda
Compare
python/cpython#150091 changed the default non-utf8 encoding from 'ascii' to 'cp437' for encoding zip filenames. This means that characters that could be encoded in cp437 but not ascii would be encoded in the zip data using cp437 vs. previously they woud've used utf-8. Note that non-ascii characters that are valid cp437 characters will always take up a single byte when encoded as cp437, but multiple when encoded using utf-8. Because `len(zipstream)` assumes that filenames are encoded using only ascii or utf-8, this resulted in the calculated length being off by (at least) 1 byte for every cp437, non-ascii character in all the filenames. The fix in this commit is to override `ZipInfo._encodeFilenameFlags` to revert Python's change and force filenames to only use ascii/utf-8. The change was made to support modifying existing zips with cp437-encoded filenames which isn't relevant to this project. And while technically cp437 is the standard encoding for zipfile names, using the more strict ascii subset is less likely to be misinterpreted by unarchivers since they won't have to guess at what extended ascii encoding was used - it'll always be strict ascii or utf-8.
pR0Ps
force-pushed
the
bugfix/length-non-asci-names
branch
from
August 20, 2026 03:38
8814cda to
012acbd
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #31