[Perl/perl5] f2af61: regex: fix recent bug with fixed utf8 substr

[email protected] (David Mitchell via perl5-changes) Wed, 29 Jul 2026 08:43:47 -0700
Newsgroups perl.perl5.changes
Message-ID <Perl/perl5/push/refs/heads/davem/gh_24614_intuit/[email protected]>
  Branch: refs/heads/davem/gh_24614_intuit
  Home:   https://github.com/Perl/perl5
  Commit: f2af617d92aa47d92ee18a229a72c43a8e78ad02
      https://github.com/Perl/perl5/commit/f2af617d92aa47d92ee18a229a72c43a8e78ad02
  Author: David Mitchell <[email protected]>
  Date:   2026-07-29 (Wed, 29 Jul 2026)

  Changed paths:
    M regexec.c
    M t/re/pat.t

  Log Message:
  -----------
  regex: fix recent bug with  fixed utf8 substr

GH #24614

v5.45.0-199-g63f838213c, while fixing a performance bug in the regex
intuit system, introduced a NULL pointer defef under certain
circumstances. In particular, where:

    - the pattern is anchored;
    - it has a fixed utf8 substring;
    - that substring can't be downgraded to non-utf8;
    - that pattern is matched against a non-utf8 string at least twice.

The cause is assuming intuit can use the fixed substring if either the
utf8 or non-utf8 is present, but then using the variant relevant to the
utf8-ness of the string being matched (which may be NULL).

The fix is trivial - retrieve the relevant substr SV first, and only use
it if it's non-NULL.

The pattern has to be matched twice due to the way S_to_byte_substr()
works: it's called the first time to attempt to downgrade the fixed and
floating substrings. Because the fixed substring can't be downgraded, it
returns false and intuit_start() abandons the effort. On second
iteration, the floating non-utf8 substr is now present, which is enough
to make intuit_start() skip calling S_to_byte_substr(). This whole area
of intuit is a bit rough.



To unsubscribe from these emails, change your notification settings at https://github.com/Perl/perl5/settings/notifications