bump csv field size limit in load_csv so long rows parse#50
Open
HrachShah wants to merge 1 commit into
Open
Conversation
The csv module's underlying C parser caps each field at 131072 bytes by default. load_csv had no protection against that, so a row with a long string (e.g. a nucleotide sequence, a large JSON blob, an embedded log line) raised an uncaught _csv.Error instead of being returned to the caller. Set csv.field_size_limit(sys.maxsize) at the top of load_csv so the parser is allowed to handle the longest field the caller can possibly give it. sys.maxsize is the platform's PY_SSIZE_T_MAX and matches the recommendation in the Python csv docs for "set the limit as high as possible" without overflowing the parser. Closes simonw#41.
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.
Closes #41.
The csv module's C parser caps each field at 131072 bytes by default.
`load_csv` had no protection against that, so a row with a long string
(e.g. a nucleotide sequence, a large JSON blob, an embedded log line)
raised an uncaught `_csv.Error: field larger than field limit (131072)`
instead of being returned to the caller.
Set `csv.field_size_limit(sys.maxsize)` at the top of `load_csv` so the
parser is allowed to handle the longest field the caller can possibly
give it. `sys.maxsize` is the platform's `PY_SSIZE_T_MAX` and matches
the recommendation in the Python csv docs
for "set the limit as high as possible" without overflowing the parser.
Tests: `tests/test_csv_diff.py` now has `test_load_csv_handles_fields_larger_than_default_limit`
(200_000-byte field) and `test_load_csv_handles_tsv_with_long_fields` (same
size, tab-separated). Both fail on master with the original `_csv.Error`
and pass with the bump. The full `tests/` suite still passes 26/26.