Repository navigation
Conversation
…only floats TerminateNumber() previously returned "" on empty/invalid inputs without clearing *np, causing numeric Parse<>() callers to form out-of-bounds pointers "" + n (C++ UB [expr.add]/4) and allowing Parse<float>/Parse<double> to accept whitespace-only strings as 0.0. Return NULL from TerminateNumber() on empty/invalid input (including after stripping leading whitespace) and check for NULL in all six Parse<>() callers, with regression tests in re2/testing/re2_test.cc.
options_.max_mem() * 2 / 3 overflows int64_t for max_mem > INT64_MAX / 2 (or < INT64_MIN / 2), triggering UBSan signed integer overflow or wrapping negative. Compute (max_mem / 3) * 2 + (max_mem % 3) * 2 / 3 instead and add RE2.MaxMemNoOverflow regression test.
This branch has not been deployed
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.
Summary
This PR fixes two bugs in
re2/re2.cc:TerminateNumber()out-of-bounds pointer arithmetic and whitespace-only float misparse (re2/re2.cc:1119-1314):TerminateNumber()previously returned""on empty/invalid inputs without clearing*np, causing all 6Parse<>()callers to compute out-of-bounds pointers"" + n(C++ UB[expr.add]/4).Parse<float>/Parse<double>(accept_spaces == true), whitespace-only strings strippednto0and returned"", wherestrtof("", &end)/strtod("", &end)returned0.0withend == str + 0anderrno == 0, causingRE2::FullMatch(" ", "(.*)", &f)to returntruewith0.0.NULLfromTerminateNumber()on empty/invalid inputs (including after stripping leading whitespace) and checkingif (str == NULL) return false;in all 6Parse<>()callers.Signed 64-bit integer overflow in
RE2::Initoptions_.max_mem() * 2 / 3(re2/re2.cc:264):options_.max_mem() * 2 / 3overflowsint64_tformax_mem > INT64_MAX / 2(or< INT64_MIN / 2), triggering UBSan signed integer overflow or wrapping negative.(max_mem / 3) * 2 + (max_mem % 3) * 2 / 3, which is algebraically identical totrunc(2 * max_mem / 3)across[INT64_MIN, INT64_MAX].Verification
-fsanitize=address,undefined -fno-sanitize-recover=all -O1 -g -DNDEBUG.RE2::FullMatch(" ", "(.*)", &f)returnedtrue(0.0);opt.set_max_mem(INT64_MAX)aborted with UBSansigned integer overflow: 9223372036854775807 * 2 cannot be represented in type 'int64_t'.re2_testpasses 79/79 (including new whitespace float/double andRE2.MaxMemNoOverflowtests).