clamp RadixStringToIeee exponent accumulation against signed overflow - #317
Merged
floitsch merged 1 commit intoSep 13, 2026
Merged
Conversation
floitsch
enabled auto-merge (squash)
September 13, 2026 15:42
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.
Problem
Similar to #310 (
clamp StringToIeee exponent accumulation against signed overflow),RadixStringToIeeeindouble-conversion/string-to-double.ccaccumulates the exponent across multiple stages without sufficient bounds:exponent -= radix_log_2without a lower floor, allowing pathologically long fractional inputs to underflowINT_MIN(signed integer overflow/underflow, which is undefined behavior).INT_MAX. When subsequently adding the parsed exponent field (exponent += written_exponent), any positivewritten_exponenttriggers signed integer overflow (INT_MAX + written_exponent).ldexp(static_cast<double>(number), exponent)with extreme exponents can trip sanitizers or platform-dependent math behavior.Solution
exponentdecrement at-(max_exponent / 2)wheremax_exponent = INT_MAX / 2, mirroring the floor inStringToIeee(clamp StringToIeee exponent accumulation against signed overflow #310).max_exponentinstead ofINT_MAX.exponentandwritten_exponentinint64_tand clamp to[-max_exponent, max_exponent].ldexpcalls by returning+/-Infinitywhenexponent > 100 * Double::kMaxExponentandSignedZero(sign)whenexponent < -100 * Double::kMaxExponent.StrToDandStrToFtotest/cctest/test-conversions.cc.