Skip to content

Comments

gh-145105: Fix crash in csv.reader with re-entrant iterator#145106

Open
raminfp wants to merge 1 commit intopython:mainfrom
raminfp:fix-gh-145105-csv-reader-reentrant-crash
Open

gh-145105: Fix crash in csv.reader with re-entrant iterator#145106
raminfp wants to merge 1 commit intopython:mainfrom
raminfp:fix-gh-145105-csv-reader-reentrant-crash

Conversation

@raminfp
Copy link
Contributor

@raminfp raminfp commented Feb 22, 2026

The fix adds a guard right after PyIter_Next returns: if
self->fields has been set to NULL by a re-entrant call, raise
csv.Error instead of continuing into parse_process_char.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant