Skip to content

Avoid Abseil hash cache crashes under ASan#634

Open
VoltVoks wants to merge 1 commit into
google:mainfrom
VoltVoks:fix-empty-absl-cache-crashes
Open

Avoid Abseil hash cache crashes under ASan#634
VoltVoks wants to merge 1 commit into
google:mainfrom
VoltVoks:fix-empty-absl-cache-crashes

Conversation

@VoltVoks
Copy link
Copy Markdown

Fixes #589.
Fixes #596.

This change avoids crashes in internal cache paths that use Abseil flat hash containers after extremely small memory budgets or failed cache setup leave those containers in an unsafe empty/zero-capacity state under ASan.

The two issue reproducers hit the same failure family:

This patch replaces the affected internal Abseil flat hash caches with standard unordered containers in the compiler and DFA cache paths, and keeps DFA::ClearCache() from iterating empty state caches. I also added regression coverage to RE2.NoCrash for both the crafted UTF-8 char-class pattern and the tiny-memory DFA teardown path.

Local verification:

ASAN_OPTIONS=detect_leaks=0 ./build-asan/re2_test --gtest_filter=RE2.NoCrash
ASAN_OPTIONS=detect_leaks=0 ./build-asan/compile_test
ASAN_OPTIONS=detect_leaks=0 timeout 30s ./build-asan/dfa_test --gtest_filter=Multithreaded.BuildEntireDFA:SingleThreaded.BuildEntireDFA:DFA.ReverseMatch:DFA.Callback
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DRE2_TEST=ON -DRE2_BENCHMARK=OFF -DRE2_BUILD_TESTING=OFF
cmake --build build -j$(nproc)
ctest --test-dir build --output-on-failure
git diff --check

Results:

RE2.NoCrash passed under ASan.
compile_test passed under ASan.
Selected DFA tests passed under ASan.
100% tests passed, 0 tests failed out of 20.
git diff --check passed.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 22, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

Segfault in RE2 compiler when compiling a crafted regex Null-deref in RE2 DFA/hash-set teardown triggered by extremely small max_mem option

1 participant