Skip to content

fix out-of-bounds write in DoubleToAscii SHORTEST_SINGLE mode - #311

Open
Ramya-9353 wants to merge 1 commit into
google:masterfrom
Ramya-9353:dtoa-shortest-single-zero
Open

fix out-of-bounds write in DoubleToAscii SHORTEST_SINGLE mode#311
Ramya-9353 wants to merge 1 commit into
google:masterfrom
Ramya-9353:dtoa-shortest-single-zero

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

AddressSanitizer, -DNDEBUG build:

==ERROR: AddressSanitizer: heap-buffer-overflow ... WRITE of size 1
    #0 DigitGen fast-dtoa.cc:387
    #1 Grisu3 fast-dtoa.cc:579
    #2 FastDtoa fast-dtoa.cc:649
    #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, e.g. DBL_MIN or 5e-324) 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 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant