gh-157379: Fix crash in csv.reader with re-entrant iterator at end of input - #157511
Open
JohannesGezachew wants to merge 1 commit into
Open
JohannesGezachew wants to merge 1 commit into
JohannesGezachew wants to merge 1 commit into
Conversation
…end of input The pythongh-145105 guard only runs after the input iterator returns a line. When a re-entrant call leaves a quoted field open and the outer call then reaches the end of input, parse_save_field() appended to the NULL fields list. Raise csv.Error in that branch too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reader_iternext_lock_held()saves a pending field when the input iterator is exhausted while a quoted field is still open. If the iterator re-entered the same reader, the inner call has already returned its row and setself->fieldstoNULL, soparse_save_field()callsPyList_Append(NULL, ...)and crashes.gh-145105 added a
self->fields == NULLcheck, but only on the path where the iterator returns a line. This adds the same check (and the samecsv.Errormessage) to the end-of-input branch, beforeparse_save_field()is called. Withstrict=Truethe existing "unexpected end of data" error is still raised first.The new test in
test_csv.pyis the reproducer from the issue: it segfaults without this change and raisescsv.Errorwith it._csv.reader: NULL deref via re-entrant iterator that reaches EOF with an open quoted field #157379