Fix crash in logging checker on a non-UTF-8 bytes format string#11111
Open
sarathfrancis90 wants to merge 1 commit into
Open
Fix crash in logging checker on a non-UTF-8 bytes format string#11111sarathfrancis90 wants to merge 1 commit into
sarathfrancis90 wants to merge 1 commit into
Conversation
The logging checker called ``bytes.decode()`` on a bytes format string, which raises ``UnicodeDecodeError`` (and crashes pylint with a fatal error) when the bytes are not valid UTF-8, e.g. ``logging.critical(b"\xc0\xc0")``. At runtime ``logging`` applies ``str()`` to the message before interpolation, so use ``str()`` here as well. This never raises and matches the string that ``logging`` actually formats. Closes pylint-dev#10813
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.
Type of Changes
Description
The logging checker crashed with a fatal
F0002error on a logging call whose format string isbytesthat isn't valid UTF-8, e.g.:_check_format_stringranformat_string.decode(), which raisesUnicodeDecodeErroron non-UTF-8 bytes.At runtime
loggingappliesstr()to the message before interpolation (str(b"\xc0\xc0")->"b'\\xc0\\xc0'"), so I switched the bytes handling tostr(format_string). That never raises and matches the stringloggingactually formats, so argument-count checks on valid bytes format strings still work.Testing: added a functional test (
logging_bytes_format_string) covering the crashing case plus valid bytes format strings with too-few/too-many args. It crashes withastroid-errorbefore the fix and passes after. All logging functional tests pass, andruff/black/isortare clean.Closes #10813