fix out-of-bounds write in DoubleToAscii SHORTEST_SINGLE mode - #311
Open
Ramya-9353 wants to merge 1 commit into
Open
fix out-of-bounds write in DoubleToAscii SHORTEST_SINGLE mode#311Ramya-9353 wants to merge 1 commit into
Ramya-9353 wants to merge 1 commit into
Conversation
AddressSanitizer, `-DNDEBUG` build:
==ERROR: AddressSanitizer: heap-buffer-overflow ... WRITE of size 1
#0 DigitGen fast-dtoa.cc:387
google#1 Grisu3 fast-dtoa.cc:579
google#2 FastDtoa fast-dtoa.cc:649
google#3 DoubleToStringConverter::DoubleToAscii double-to-string.cc:427
0 bytes after 10-byte region
Reached from `DoubleToAscii(DBL_MIN, SHORTEST_SINGLE, 0, buf, 10, ...)`, a
conforming call: the header only forbids static_cast<float>(v) being NaN or
+/-Infinity, and a positive double below the smallest float (0 < v < 2^-150)
casts to a finite +0.0f. Grisu3 then takes the shortest-single boundaries from
Single(0.0f).NormalizedBoundaries(), violating its value > 0 precondition, so
DigitGen emits about 20 digits at the double's magnitude into the 10-byte
(kBase10MaximalLengthSingle + 1) buffer.
The existing zero special-case only catches an exact double zero. Extend it so
SHORTEST_SINGLE also emits "0" when the value rounds to a single zero, the way
an actual single zero already renders.
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.
AddressSanitizer,
-DNDEBUGbuild:Reached from
DoubleToAscii(DBL_MIN, SHORTEST_SINGLE, 0, buf, 10, ...), a conforming call: the header only forbidsstatic_cast<float>(v)being NaN or +/-Infinity, and a positive double below the smallest float (0 < v < 2^-150, e.g.DBL_MINor5e-324) casts to a finite +0.0f. Grisu3 then takes the shortest-single boundaries fromSingle(0.0f).NormalizedBoundaries(), violating its value > 0 precondition, so DigitGen emits about 20 digits at the double magnitude into the 10-byte (kBase10MaximalLengthSingle + 1) buffer.The existing zero special-case only catches an exact double zero. Extend it so SHORTEST_SINGLE also emits "0" when the value rounds to a single zero, the way an actual single zero already renders. Regression case added beside the existing SHORTEST_SINGLE tests in test-dtoa.cc.