Skip to content

Check for the subject end before the first start-bits load - #985

Merged
NWilson merged 2 commits into
PCRE2Project:mainfrom
mattst88:jit-start-bits-end-check
Sep 13, 2026
Merged

NWilson merged 2 commits into
PCRE2Project:mainfrom
mattst88:jit-start-bits-end-check

Conversation

@mattst88

Copy link
Copy Markdown
Contributor

The Alpha and x86-64 start-bits scans checked STR_PTR against STR_END before
their first load only when the offset was nonzero. mainloop_entry() can
advance STR_PTR to STR_END before calling the scan, and if STR_END is on a
page boundary the aligned load then reads the next page. Check the end of the
subject unconditionally.

Tested on Alpha under qemu-alpha with the subject placed right before an
unmapped page: patterns such as [a-c](?=\d) against zzzzzzza fault
without the fix and return no match with it. pcre2_jit_test and RunTest
pass on Alpha, and ctest passes on x86-64.

Fixes #984

fast_forward_start_bits_simd() checked STR_PTR against STR_END before its
first load only when the offset was nonzero. mainloop_entry() can advance
STR_PTR to STR_END before calling it, and if STR_END is on a page boundary
the aligned load then reads the next page, which faults when that page is
unmapped.
fast_forward_start_bits_simd() checked STR_PTR against STR_END before its
first load only when the offset was nonzero. mainloop_entry() can advance
STR_PTR to STR_END before calling it, and if STR_END is on a page boundary
the aligned load then reads the next page, which faults when that page is
unmapped.

Fixes PCRE2Project#984
@NWilson

NWilson commented Sep 12, 2026

Copy link
Copy Markdown
Member

Great! Unconditional checks are safe, and it's fixed in both sites.

I'm very disturbed by the fact that the OpenBSD build is the only one that caught this. We test with valgrind in our CI, which has pretty similar checks for overreads. But nothing failed in CI.

That seems to be because the entire JIT SIMD code is removed when SUPPORT_VALGRIND is defined: and our CI makes sure to turn on the Valgrind build-time support when we run the tests under Valgrind!

@zherczeg - Surely we should fix that, right? This issue is caught immediately on Linux when we run ./RunTest -valgrind on a build where SUPPORT_VALGRIND=OFF. But we don't test that configuration.

Nor should we test that configuration! Shouldn't we just remove #if !(defined SUPPORT_VALGRIND) in pcre2_jit_simd_inc.h?

@zherczeg zherczeg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NWilson
NWilson merged commit 833d0e8 into PCRE2Project:main Sep 13, 2026
40 checks passed
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.

The new x86 JIT start-bitmap scan can read past (at) the subject end

3 participants