Fix crash parsing non-finite numbers (inf/nan) in namelists - #45
Open
jacquelinegarrahan wants to merge 1 commit into
Open
Fix crash parsing non-finite numbers (inf/nan) in namelists#45jacquelinegarrahan wants to merge 1 commit into
jacquelinegarrahan wants to merge 1 commit into
Conversation
try_int() called int(x) unconditionally, which raises OverflowError on
infinities and ValueError on NaN. number('inf'), number('nan'), and
overflowing exponents like '1e400' therefore crashed the namelist
parser on valid Fortran/Astra/Impact numeric output. Guard the int()
conversion and return the float unchanged when it is not integral.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fix crash parsing non-finite numbers in namelists
Branch:
bugfix/namelist-nonfinite-numbers→mainBug
lume/parsers/numbers.py::try_intconverts a float tointunconditionally:number()routes every float-like token throughtry_int(float(z)), so anytoken that
float()accepts butint()cannot convert crashes the parser:"inf"OverflowErrorinf"-inf"OverflowError-inf"nan"ValueErrornan"1e400"OverflowErrorinfBoth single-value (
parse_unrolled_namelistline 123) and vector (line 127)paths call
number(), so a namelist file containing e.g.b = Inf— whichappears in real Fortran/Astra/Impact numeric output — crashed the whole parse.
The
numbers.py/namelist.pyparsers have no test coverage, so this slippedthrough.
Fix
Guard the
int()conversion intry_intand return the value unchanged when itis not a finite integer. Integral floats (
1.0 -> 1) and strings are unaffected.Verification
🤖 Generated with Claude Code