This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: assertion failure in Parser/string_parser.c
Type: crash Stage: resolved
Components: Parser Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: eric.smith, gregory.p.smith, lys.nikolaou, miss-islington, pablogsal
Priority: high Keywords: patch

Created on 2022-01-24 18:30 by gregory.p.smith, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30865 merged eric.smith, 2022-01-25 02:25
PR 30866 merged miss-islington, 2022-01-25 02:53
PR 30867 merged miss-islington, 2022-01-25 02:53
PR 30883 closed eric.smith, 2022-01-25 12:17
Messages (10)
msg411503 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2022-01-24 18:30
```
>>> v = r"""f'\N  '"""
>>> import ast
>>> ast.literal_eval(v)
python: ../gpshead/Parser/string_parser.c:487: fstring_find_literal: Assertion `s == end || *s == '{' || *s == '}'' failed.
Aborted
```

this comes from oss-fuzz after enabling assert checks in its cpython builds. :)

https://oss-fuzz.com/testcase-detail/4805529363415040 & https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=43730 for those who have access.
msg411510 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-24 19:18
Adding Eric as this seems to be in the f-string parser.
msg411511 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-24 19:18
I'll take a look.
msg411531 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-24 23:29
This triggers the same problem:
f'\N  '
ast.literal_eval() isn't needed.

I think it's just the assert that's wrong, but I'm still checking.
msg411548 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-25 02:44
Note that f'\N ' (with a single space) isn't enough to trigger this behavior. It requires at least two characters after the '\N'. The first is when the invalid string is recognized, and it's the presence of the second character that triggers the failed assert.
msg411549 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-25 02:53
New changeset 0daf72194bd4e31de7f12020685bb39a14d6f45e by Eric V. Smith in branch 'main':
bpo-46503: Prevent an assert from firing when parsing some invalid \N sequences in f-strings. (GH-30865)
https://github.com/python/cpython/commit/0daf72194bd4e31de7f12020685bb39a14d6f45e
msg411550 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-25 03:08
New changeset c314e3e829943b186e1c894071f00c613433cfe5 by Miss Islington (bot) in branch '3.9':
bpo-46503: Prevent an assert from firing when parsing some invalid \N sequences in f-strings. (GH-30865) (30867)
https://github.com/python/cpython/commit/c314e3e829943b186e1c894071f00c613433cfe5
msg411551 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-25 03:13
New changeset 894e8c13484822458d53cc77c9265b7a88450a4b by Miss Islington (bot) in branch '3.10':
bpo-46503: Prevent an assert from firing when parsing some invalid \N sequences in f-strings. (GH-30865) (GH-30866)
https://github.com/python/cpython/commit/894e8c13484822458d53cc77c9265b7a88450a4b
msg411593 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-01-25 14:28
Thanks for the quick fix, Eric!
msg412048 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2022-01-29 03:21
In case anyone cares: in a non-debug build, this error had no real effect. It just caused the "find the literal part of an fstring" routine to terminate early, but since the part that it had already identified was still in error, a syntax error was still raised.

For "\Nxy" it would terminate at "\Nx", instead of consuming the whole string. But since "\Nx" isn't a valid string (bad unicode name escape), it would raise the same syntax error as "\Nxy".
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90661
2022-01-29 03:21:39eric.smithsetmessages: + msg412048
2022-01-25 14:28:02pablogsalsetmessages: + msg411593
2022-01-25 12:17:04eric.smithsetpull_requests: + pull_request29064
2022-01-25 03:14:13eric.smithsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-01-25 03:13:19eric.smithsetmessages: + msg411551
2022-01-25 03:08:50eric.smithsetmessages: + msg411550
2022-01-25 02:53:42miss-islingtonsetpull_requests: + pull_request29048
2022-01-25 02:53:38eric.smithsetmessages: + msg411549
2022-01-25 02:53:37miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request29047
2022-01-25 02:44:26eric.smithsetmessages: + msg411548
2022-01-25 02:25:50eric.smithsetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request29046
2022-01-24 23:29:14eric.smithsetmessages: + msg411531
2022-01-24 19:18:55eric.smithsetmessages: + msg411511
2022-01-24 19:18:45eric.smithsetassignee: pablogsal -> eric.smith
2022-01-24 19:18:02pablogsalsetmessages: + msg411510
2022-01-24 19:17:33pablogsalsetnosy: + eric.smith
2022-01-24 18:32:27gregory.p.smithsetassignee: pablogsal
2022-01-24 18:30:42gregory.p.smithcreate