Repository navigation
fix: encode input as UTF-8 bytes in adler32 to match the Adler-32 spec - #15706
Open
Ankushkushwaha1 wants to merge 1 commit into
Open
Ankushkushwaha1 wants to merge 1 commit into
Ankushkushwaha1 wants to merge 1 commit into
Conversation
…lgorithms#15635) The Adler-32 algorithm is defined over a byte stream. The previous implementation iterated Unicode code points via ord(char), which produced correct results only for pure-ASCII input. For any non-ASCII character (e.g. '€', '日') the checksum diverged from every standard Adler-32 implementation including Python's own zlib.adler32. Fix: encode the input string as UTF-8 first and iterate over the resulting bytes, mirroring what hashes/crc32.py already does. Added two new doctests with non-ASCII strings that verify the output matches zlib.adler32.
This branch has not been deployed
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.
Description
Fixes #15635
The Adler-32 algorithm is defined over a byte stream. The previous implementation iterated over Unicode code points via
ord(char), which produced correct results only for pure-ASCII input. For any non-ASCII character (e.g.'€','日本語') the checksum silently diverged from every standard Adler-32 implementation, including Python's ownzlib.adler32.Root Cause
Fix
Encode the input string to UTF-8 first, then iterate over the resulting bytes — exactly what
hashes/crc32.pyalready does:Verification
Checklist
'Algorithms'→ 363791387,'go adler em all'→ 708642122)zlib.adler32