Title: gh-145234: Fix SystemError in parser when \r is introduced after code… by gourijain029-del · Pull Request #145276 · python/cpython · GitHub
Open Graph Title: gh-145234: Fix SystemError in parser when \r is introduced after code… by gourijain029-del · Pull Request #145276 · python/cpython
X Title: gh-145234: Fix SystemError in parser when \r is introduced after code… by gourijain029-del · Pull Request #145276 · python/cpython
Description: Description This PR fixes a SystemError: Parser/string_parser.c:286: bad argument to internal function that occurred when a Python file used an encoding (like UTF-7) that introduced \r characters after decoding. Root Cause The crash was caused by a synchronization failure between the tokenizer, the lexer, and the string parser: Tokenizer: When the file tokenizer recoded a line (e.g., from UTF-7 to UTF-8), it was not normalizing newlines. If the codec introduced a \r, it remained in the buffer. Lexer: The lexer skipped \r characters but did not correctly trigger "beginning-of-line" (atbol) logic. This meant that if a \r followed a comment (#...), the lexer would remain in a state where it thought it was still on the same line, causing it to merge the comment and the subsequent string literal into a single, invalid token. String Parser: When _PyPegen_parse_string received this broken token (which didn't start with a quote character), it raised a SystemError. Changes Parser/lexer/lexer.c : Updated the lexer to treat a standalone \r as a full newline. It now correctly sets atbol = 1 and resets the current token start, preventing the "merging" of tokens across lines. Parser/tokenizer/file_tokenizer.c : Updated tok_readline_recode to explicitly call _PyTokenizer_translate_newlines on the UTF-8 decoded buffer. Optimized tok_underflow_file to immediately discard and re-decode the buffer as soon as a coding spec is identified, preventing raw bytes from leaking into the parser. Lib/test/test_parser_utf7_r.py : Added a new regression test that uses a UTF-7 encoded \r to reproduce the original crash. Issue: gh-145234
Open Graph Description: Description This PR fixes a SystemError: Parser/string_parser.c:286: bad argument to internal function that occurred when a Python file used an encoding (like UTF-7) that introduced \r characters a...
X Description: Description This PR fixes a SystemError: Parser/string_parser.c:286: bad argument to internal function that occurred when a Python file used an encoding (like UTF-7) that introduced \r characters a...
Opengraph URL: https://github.com/python/cpython/pull/145276
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:81b2eca8-18e6-fa27-52c7-45934256aa36 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BA66:12AF6:24E2069:336DDF4:6A50C28B |
| html-safe-nonce | 3b913941617b00fae1685a7eedfe27f06617a52006340b3dbb5cfd34fa50a6b4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTY2OjEyQUY2OjI0RTIwNjk6MzM2RERGNDo2QTUwQzI4QiIsInZpc2l0b3JfaWQiOiI1NjY5OTgyMTY2ODU3MDczMjkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1241a554eb41e01aed0f5c312e99505f2ec3292658965a1e1bfd6f02c091f718 |
| hovercard-subject-tag | pull_request:3332909382 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/145276/files |
| twitter:image | https://avatars.githubusercontent.com/u/235066236?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/235066236?s=400&v=4 |
| og:image:alt | Description This PR fixes a SystemError: Parser/string_parser.c:286: bad argument to internal function that occurred when a Python file used an encoding (like UTF-7) that introduced \r characters a... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 72b13e0e8d0319acdd27a145cfe73f4f06c791713d0ac4690e41fb68ad28cac0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 08e79d53fc070870d5b168356afebb1e286a2ffe |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width