Repository navigation
_set_str missing NULL check after PyUnicode_DecodeASCII in _csv.c #146093
Copy link
Copy link
Closed
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Activity
- addedextension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on Mar 17, 2026 I wrote #146113 to fix the issue.
- added3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes
on Mar 18, 2026 - added a commit that references this issue
on Mar 18, 2026 Issue fixed by #146113. Thanks for the bug report.
- marked
_csv:_set_str()missing NULL check afterPyUnicode_DecodeASCII()#145978 as a duplicate of this issueon Mar 18, 2026 I'm certainly no expert on crashers, but would it have been possible to add a unit test for this? Even @devdanzin's report code would seem to have been helpful.
Causing PyUnicode_DecodeASCII() to fail with a memory allocation failure requires to tune
_testcapi.set_nomemory()exactly, but theset_nomemory()argument can vary over time if Python internals change.I don't think that we can write a reliable test with reasonable maintenance.
Reacted by Skip Montanaro
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Crash report
What happened?
It's possible to segfault the interpreter on OOM by trying to write a CSV row.
Automated diagnosis:
Bug: On OOM,
PyUnicode_DecodeASCIIreturnsNULL,_set_strstoresNULLin*targetand returns 0 (success). LaterPyUnicode_GET_LENGTH(NULL)segfaults.File: Modules/_csv.c, line 319
MRE:
Backtrace:
Found using cpython-review-toolkit with Claude Opus 4.6, using the
/cpython-review-toolkit:explore Modules/_csv.c all deepcommand.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.15.0a7+ (heads/main:e0f7c1097e1, Mar 17 2026, 18:10:52) [Clang 21.1.2 (2ubuntu6)]
Linked PRs