Repository navigation
fix: avoid IndexError in is_mostly_bin for short tails - #8196
Merged
mhils merged 2 commits intoApr 25, 2026
Merged
Conversation
`is_mostly_bin` looks up to 4 bytes past the 100-byte cutoff to find a clean UTF-8 character boundary. when the input is just over 100 bytes and starts with a continuation byte at index 100, the lookahead reads past the end of the buffer. cap the loop end at `len(s)`. existing fallback to `s[:100]` still covers the case where every byte in the lookahead window is a continuation byte. fixes #8188
Contributor
Author
|
🫡 |
1 of 2 tasks
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 #8188.
reproducible with any bytes payload of len 101–103 where index 100 is a UTF-8 continuation byte:
the lookahead loop
range(100, 104)readss[100]throughs[103]to find the start of the next UTF-8 char and avoid chopping a multibyte code point in half. when len(s) is between 101 and 103 and the first byte past the 100-byte cutoff is a continuation byte, the loop continues into out-of-range indices.cap the loop end at
len(s). the existings[:100]fallback still covers the case where every byte in the lookahead window is a continuation byte.added a small regression assertion for the three affected lengths.