Repository navigation
Validate field size after reading the whole record - #382
Merged
Merged
Conversation
GitHub: Fix rubyGH-381 A max_field_size error skipped only the rest of the physical line. In parse_quotable_robust, the rest of a record that has a quoted field spanning lines was returned as the next row or raised another error. In parse_quotable_loose and parse_no_quote, the line was already read, so the next line was skipped too, and CSV#line raised TypeError when the error was in the first row. Validate field sizes in emit_row instead. All parsers call it after reading the whole record, so nothing needs to be skipped and CSV#line returns the whole broken record. If the record has another error after the long field, such as an unclosed quoted field, that error is raised instead, as it is without max_field_size. The field_size_limit document said that it limits how much CSV reads ahead and prevents DoS attacks. It wasn't true even with the old line based parser: it read a whole line without limit and stopped reading only lines of an unclosed quoted field. The current parser doesn't stop reading at all. Remove it from the document and add a document for max_field_size that says it doesn't limit how much CSV reads. Reported by William T. Nelson. Thanks!!! Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
With Perhaps that error should be fatal. |
Member
Author
|
Good point. Let's work on it as a separated task. |
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.
GitHub: Fix GH-381
A max_field_size error skipped only the rest of the physical line. In parse_quotable_robust, the rest of a record that has a quoted field spanning lines was returned as the next row or raised another error. In parse_quotable_loose and parse_no_quote, the line was already read, so the next line was skipped too, and CSV#line raised TypeError when the error was in the first row.
Validate field sizes in emit_row instead. All parsers call it after reading the whole record, so nothing needs to be skipped and CSV#line returns the whole broken record.
If the record has another error after the long field, such as an unclosed quoted field, that error is raised instead, as it is without max_field_size.
The field_size_limit document said that it limits how much CSV reads ahead and prevents DoS attacks. It wasn't true even with the old line based parser: it read a whole line without limit and stopped reading only lines of an unclosed quoted field. The current parser doesn't stop reading at all. Remove it from the document and add a document for max_field_size that says it doesn't limit how much CSV reads.
Reported by William T. Nelson. Thanks!!!