reject negative fractional_count in FastFixedDtoa - #315
Merged
floitsch merged 1 commit intoSep 10, 2026
Conversation
FastFixedDtoa only validated that fractional_count <= 20, but did not reject negative values (fractional_count < 0). While DoubleToStringConverter::ToFixed rejects negative requested_digits before calling FastFixedDtoa (PR google#298), a direct caller of FastFixedDtoa passing a negative fractional_count could succeed and write integer digits into the output buffer, potentially overrunning smaller buffers. Reject fractional_count < 0 by returning false and ensure *length is reset to 0, matching the behavior in FastDtoa (PR google#313). Add a test in test-fixed-dtoa.cc.
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
FastFixedDtoaonly validated thatfractional_count <= 20, but did not check for negative values (fractional_count < 0).While
DoubleToStringConverter::ToFixedguards against negativerequested_digits(PR #298), direct callers ofFastFixedDtoapassing a negativefrractional_countcould succeed and write integer digits into the buffer, potentially overrunning small buffers. In addition, whenFastFixedDtoareturnedfalse,*lengthwas left uninitialized.Solution
*length = 0;is set at the start ofFastFixedDtoa.fractional_count < 0alongsidefractional_count > 20by returningfalse, matching the guard pattern inFastDtoa(PR guard non-positive requested_digits in DigitGenCounted #313).FastFixedDtoaNegativeFractionalCountintest/cctest/test-fixed-dtoa.ccto verify that negative fractional counts fail and do not touch the buffer.