Branch: refs/heads/yves/fix_24816
Home: https://github.com/Perl/perl5
Commit: de68606cb259ce8ed4ba6aff2dd003a0899d17a3
https://github.com/Perl/perl5/commit/de68606cb259ce8ed4ba6aff2dd003a0899d17a3
Author: Yves Orton <[email protected]>
Date: 2026-09-14 (Mon, 14 Sep 2026)
Changed paths:
M regcomp.h
M regcomp_trie.c
M regexec.c
M t/re/regexp.t
Log Message:
-----------
regcomp_trie: make octet trie lookups always valid
Fix intermittent segfaults from the trie logic, as reported in #24816,
and discussed in #24814.
The list compiler previously recorded a slot after a sparse frame in
lasttrans without always allocating or clearing it. A lookup could
therefore treat uninitialized transition data as belonging to its state
and use an arbitrary next state.
This issue affected all platforms but was most prominently visible on
Windows and Cygwin. (Historically Windows realloc is not as good as
*nix realloc.)
As part of fixing this, I reworked some of the logic to be more robust
and ensure we never see this kind of issue again.
We give the root state the complete octet frame at slots 1 through 256.
Other states can reuse unoccupied root slots. Each state base maps octet
zero to an offset not less than 1, and we ensure there are enough valid
null transitions at the end, so we never read a bogus transition and do
not need to do bounds checks either.
While working on this I noticed we had some logic left over from the old
implementation that still used the concept of "charid", which confused
matters. This was removed, and we now have simpler runtime logic to do
transition lookups.
I also added code to validate the state and transition indexes under
DEBUG_r. Move that block outside DEBUG_r when validation is wanted in
every full DEBUGGING build. Thus, compilation under C<use re 'debug'>
also exercises the transition validation, so if you suspect a related
bug try the pattern under that pragma.
Added support to regexp.t to allow the developer to select an inclusive
range of re_tests input lines while retaining its original TAP numbering.
This makes the triggering cases practical to stress independently.
The re_tests lines 2221 through 2222 also pass with 100,000 iterations,
including under ASAN with a refcounted stack (PERL_RC_STACK).
To unsubscribe from these emails, change your notification settings at
https://github.com/Perl/perl5/settings/notifications