reject invalid UTF-8 sequences in _zip_guess_encoding - #547
Merged
Conversation
Member
|
Thank you, good points. |
Contributor
Author
|
Happy to. I pulled the lead-byte extraction into each length branch so the low bits are masked off with the matching UTF_8_LEN_*_MASK, which drops the shifted-0x3f trick that was misbehaving in the 1-byte case. The continuation payload now uses a named UTF_8_CONTINUE_VALUE_MASK instead of the bare 0x3f. Full regress suite still passes, and the surrogate test still rejects as before. |
Member
|
Thank you, merged! |
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.
The UTF-8 detection in _zip_guess_encoding only checks the length pattern of the lead byte and the high bits of the continuation bytes, so it treats overlong encodings, surrogate halves (U+D800 to U+DFFF), and code points above U+10FFFF as valid UTF-8. That lets a filename or comment marked UTF-8 (general purpose bit 11) slip past the validation zip_open performs, even though libzip means to reject invalid UTF-8 there with ZIP_ER_INCONS. This decodes the code point while scanning the continuation bytes and rejects those three cases so the existing check fires; valid multibyte names are unaffected. Added a regress case that opens a crafted archive whose name is the encoded surrogate half U+D800.