Repository navigation
Conversation
…se DFA In DFA::InlinedSearchLoop(), when run_forward is false, p decrements on every step so p < resetp on subsequent state-cache flushes. Casting the negative ptrdiff_t (p - resetp) to size_t wrapped near SIZE_MAX, making the < 10*state_cache_.size() slow-bailout condition always false and preventing a thrashing reverse DFA from falling back to the NFA. Use run_forward ? p - resetp : resetp - p and add regression test DFA.ReverseBailoutWhenSlow in re2/testing/dfa_test.cc.
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
In
DFA::InlinedSearchLoop()(re2/dfa.cc:1439-1444), when the DFA state cache fills and flushes repeatedly, RE2 checks progress since the previous flush so a thrashing DFA can bail out to the NFA:When
run_forward == false(reverse DFA search),pdecrements on every byte (c = *--p,re2/dfa.cc:1406) andcan_prefix_accelis strictlyfalse(re2/compile.cc:1180). Thus on every cache flush after the first,bp <= p < resetp < bp + size, makingp - resetpstrictly negative. Casting the negativeptrdiff_ttosize_twraps nearSIZE_MAX, so< 10*state_cache_.size()is alwaysfalseand a thrashing reverse DFA never bails out to the NFA.Fix
static_cast<size_t>(run_forward ? p - resetp : resetp - p)inre2/dfa.cc:1440.DFA.ReverseBailoutWhenSlowinre2/testing/dfa_test.cc.Verification
-fsanitize=address,undefined -fno-sanitize-recover=all -O1 -g -DNDEBUG.^[01]{18}0withDeBruijnString(18),ReverseProgran 1,291 state-cache resets and never bailed out (failed=0).ReverseProgbails out after 1 reset (failed=1, resets=1, failures=1);dfa_testpasses 7/7 with 0 warnings and 0 ASan/UBSan errors.