Repository navigation
🐛 fix(encoding): reject encoding labels with NUL - #2274
Merged
Merged
Conversation
The encoding= label was matched as a C string in the table search, so a label with an embedded NUL matched the table entry for the text before the NUL. A label such as "latin1" followed by a NUL and more text was accepted and decoded as windows-1252, although the label is not a valid encoding name. The lookup now refuses any label that contains a NUL, and the LookupError shows the whole label instead of the text before the NUL. Fixes tox-dev#2269
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.
An
encoding=label that contains a NUL byte was accepted, and the label was matched as though the NUL were the end of the string.parse(b"<p>\xe9</p>", encoding="latin1\x00junk")decoded the document aswindows-1252, even though the label names no encoding. The lookup now refuses such a label, so the call raises the sameLookupErroras any other unknown label. Fixes #2269.The table search stopped at the NUL
The label lookup trims ASCII whitespace, lowercases the label into a C string, and searches the encoding table with C string comparisons. A NUL inside the label therefore ended the comparison early, and
latin1matched. Any label with a NUL, whether before, inside or after the name, now returns no entry.The error message stopped at the NUL
The unknown-label error formatted the label with
%s, so a rejected label showed only the text before its NUL, which read as thoughlatin1were unknown. The message now formats the full label.Behavior changes
Labels without a NUL behave as before. A label with a NUL raises
LookupErrorwhere it used to be accepted, and the message shows the full label text.