]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106)
authorRamin Farajpour Cami <ramin.blackhat@gmail.com>
Sat, 11 Apr 2026 22:18:02 +0000 (01:48 +0330)
committerGitHub <noreply@github.com>
Sat, 11 Apr 2026 22:18:02 +0000 (15:18 -0700)
commit20994b1809f9c162e4cae01a5af08bd492ede9f9
treedbaf813cb60a911f4ee4b5a5295845b131f042da
parentc29d75610b40d2052dc7a5394b416305adf61281
gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106)

When a custom iterator calls next() on the same csv.reader from
within __next__, the inner iteration sets self->fields to NULL.
The outer iteration then crashes in parse_save_field() by passing
NULL to PyList_Append.

Add a guard after PyIter_Next() to detect that fields was set to
NULL by a re-entrant call, and raise csv.Error instead of crashing.
Lib/test/test_csv.py
Misc/NEWS.d/next/Library/2026-02-22-00-00-00.gh-issue-145105.csv-reader-reentrant.rst [new file with mode: 0644]
Modules/_csv.c