BUG: Fix segfault in read_csv with extremely large exponents #63098
+63
−1
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 #63089
Description
This PR fixes a segmentation fault that occurs when reading CSV files containing numbers with extremely large exponents in scientific notation (e.g.,
4e492493924924).Root Cause
The issue was an integer overflow in the
xstrtod()function inpandas/_libs/src/parser/tokenizer.c. When parsing the exponent portion of scientific notation, the code accumulated digits into anintvariable without bounds checking:With an exponent like
492493924924, the variablenwould overflow, causing undefined behavior that manifests as a segmentation fault.Solution
I added a maximum digit cap (
MAX_EXPONENT_DIGITS = 4) when accumulating the exponent value:DBL_MIN_EXPtoDBL_MAX_EXP) will properly handle out-of-range valuesTesting
Added
test_issue_63089.pywith test cases covering:The fix prevents the overflow while maintaining correct parsing behavior for valid scientific notation.
Checklist: