]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106) (...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 11 Apr 2026 22:46:26 +0000 (00:46 +0200)
committerGitHub <noreply@github.com>
Sat, 11 Apr 2026 22:46:26 +0000 (22:46 +0000)
commit4f8a77bf3fa8d0c10ddd50a8dda4ad89e8d2434e
tree812e9f40e547f7c52d23db334f7370caa0670be5
parentd6be9fb07731efaaf70027b38cfc752caa0b91d2
[3.14] gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106) (#148404)

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.
(cherry picked from commit 20994b1809f9c162e4cae01a5af08bd492ede9f9)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
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