Skip to content

[3.13] gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106)#148405

Merged
gpshead merged 1 commit intopython:3.13from
miss-islington:backport-20994b1-3.13
Apr 11, 2026
Merged

[3.13] gh-145105: Fix crash in csv.reader with re-entrant iterator (GH-145106)#148405
gpshead merged 1 commit intopython:3.13from
miss-islington:backport-20994b1-3.13

Conversation

@miss-islington
Copy link
Copy Markdown
Contributor

@miss-islington miss-islington commented Apr 11, 2026

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 20994b1)

Co-authored-by: Ramin Farajpour Cami ramin.blackhat@gmail.com

…thonGH-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 20994b1)

Co-authored-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
@gpshead gpshead enabled auto-merge (squash) April 11, 2026 22:20
@gpshead gpshead merged commit 8e369d3 into python:3.13 Apr 11, 2026
46 checks passed
@miss-islington miss-islington deleted the backport-20994b1-3.13 branch April 11, 2026 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants