The patch for CVE-2026-8376 is six lines of arithmetic-overflow guard added to Perl_study_chunk in regcomp_study.c. Five of those lines are a renamed copy of code already in the same function, two hundred lines earlier, guarding a different mincount multiplication against the same SSize_t_MAX ceiling and ending in the same FAIL("Regexp out of space") string literal. John Lightsey committed the first check on 20 November 2019, in a commit titled "Prevent integer overflow from nested regex quantifiers." Tony Cook committed the second check on 12 May 2026, after Timothy Legge reported that Perl_study_chunk was heap-overflowing on every 32-bit build of Perl 5.43.10 and earlier. Six years and six months separate the two checks in the same function.
CVE-2026-8376: The Overflow Check Was Already In Perl_study_chunk
vendor
pattern
cve
proof of concept
The patch for CVE-2026-8376 is six lines of arithmetic-overflow guard added to Perl_study_chunk in regcomp_study.c. Five of those lines are a renamed copy of code already in the same function, two hundred lines earlier, guarding a different mincount multiplication against the same SSize_t_MAX ceiling and ending in the same FAIL("Regexp out of space") string literal. John Lightsey committed the first check on 20 November 2019, in a commit titled "Prevent integer overflow from nested regex quantifiers." Tony Cook committed the second check on 12 May 2026, after Timothy Legge reported that Perl_study_chunk was heap-overflowing on every 32-bit build of Perl 5.43.10 and earlier. Six years and six months separate the two checks in the same function.
The check was already in the file
Perl_study_chunk is Perl's regex optimizer. The function walks a compiled regex tree and computes properties the matcher will use to skip ahead: minimum match length, fixed-substring anchors, character-class invariants. When it sees a quantifier with a known minimum repetition count, it has to do at least two pieces of arithmetic. The first is a length accumulator. The second is a buffer sizer.
The length accumulator is at line 2587, and since November 2019 it has been guarded:
if ( ( minnext > 0 && mincount >= SSize_t_MAX / minnext )
|| min >= SSize_t_MAX - minnext * mincount )
{
FAIL("Regexp out of space");
}
min += minnext * mincount;This is the canonical signed-multiply overflow guard, written exactly the way a careful C programmer writes it. The first clause guards against mincount * minnext overflowing SSize_t. The second clause guards against the cumulative sum overflowing once added. If either check fires, the regex is rejected at compile time with the user-facing message Regexp out of space. The check exists. The check works. The check is in Perl_study_chunk because the person who put it there understood that mincount is whatever the user wrote inside {...} in their regex, that SSize_t is 32 bits wide on a 32-bit build, and that the obvious arithmetic between the two will overflow if the user picks bad numbers.
Two hundred lines below Lightsey's guard, the same function does the second piece of arithmetic. Until 12 May 2026, the second site was unguarded.
The second arithmetic site is older than the guard
When study_chunk finishes accumulating a fixed substring and discovers it sits inside a quantifier with mincount > 1, it materializes the repeated string into data->last_found so the matcher can use it as a forward anchor. The pre-patch code reads:
if (deltanext == 0 && pos_before == b) {
/* What was added is a constant string */
if (mincount > 1) {
SvGROW(last_str, (mincount * l) + 1);
repeatcpy(SvPVX(last_str) + l,
SvPVX_const(last_str), l,
mincount - 1);
SvCUR_set(last_str, SvCUR(last_str) * mincount);l is the byte length of the substring. mincount is the user's quantifier. mincount * l is the size of the buffer the function is about to allocate via SvGROW. repeatcpy then writes l * (mincount - 1) more bytes into that buffer starting at offset l.
If mincount * l overflows SSize_t, SvGROW is called with the truncated low bits of the product. repeatcpy is called with the full untruncated counts. The write lands wherever the allocator put the now-undersized buffer.
git blame puts the SvGROW(last_str, (mincount * l) + 1) line in Chip Salzenberg's "Jumbo regexp patch applied" commit from 15 November 1997. It is twenty-eight years and six months old. Lightsey's overflow guard, two hundred lines up in the same function, is six years and six months old. The bug pre-dates the protective pattern by more than two decades, and the protective pattern has been visible in the same function for over half a decade without being applied to the second site.
The fix is commit 5e7f119:
if (l > 0 &&
(mincount >= SSize_t_MAX / (SSize_t)l
|| old > SSize_t_MAX - mincount * (SSize_t)l)) {
FAIL("Regexp out of space");
}Lay it against Lightsey's check. Same function, same SSize_t_MAX ceiling, same two-clause structure (guard the multiplication, guard the accumulator), same FAIL("Regexp out of space") literal. Lightsey's variables are minnext and min. Cook's are l and old. Cook's site needs an explicit (SSize_t) cast because l is STRLEN rather than signed. The algebra is identical. Cook's check is Lightsey's check, applied to the second arithmetic site in the same function, six and a half years after the first.
The PoC is one regex
The seclists.org disclosure included no PoC. The test commit on the security branch (e842efd, 12 May 2026) is the PoC, and it is also the canonical exercise of the second arithmetic site:
/\x{10000}{1073741824}/\x{10000} is the smallest Unicode codepoint that requires four bytes in UTF-8. {1073741824} is 2**30. The regex is one four-byte character, repeated 2**30 times.
Perl_study_chunk reaches the second arithmetic site with l = 4 and mincount = 1073741824. The intended buffer size is 4 * 1073741824 = 2**32 bytes. SSize_t_MAX on a 32-bit build is 2**31 - 1. mincount * l overflows to 0. SvGROW(last_str, 0 + 1) allocates a one-byte payload. repeatcpy then writes roughly 4 * (1073741824 - 1) bytes past the end of it.
The same commit ships a second test in case the first is dismissed as a corner of a corner:
/(?:\x{10001}\x{10000}){536870912}/536870912 is 2**29. The grouped substring is two four-byte UTF-8 characters. l = 8, mincount = 2**29. The product is again 2**32. The arithmetic that overflowed once overflows the same way with different operands.
A 32-bit Perl process that compiles either of these patterns from attacker-controlled input dies in a heap write. The CVE is rated 9.8 because the compile step runs inside whatever interpreter the operator handed an untrusted regex to: a web app accepting a search pattern, a log parser loading grok rules from disk, a CI pipeline taking a regex flag, a CGI script that exposes a --filter query parameter. The compile is the attack surface.
What the test commit admitted
The test commit e842efd shipped the two PoC patterns wrapped in:
SKIP:
{ # sec #147
$Config{ptrsize} == 4
or skip "these only fail on x32 and use too much memory on x64", 2;
local $::TODO = "This crashes";
# original case
fresh_perl_like('/\x{10000}{1073741824}/',
qr/Regexp out of space/, {}, "ssize_t overflow");$::TODO = "This crashes" is Test::More's marker for a test the maintainer expects to fail. The line is committed admission that on the day the test landed, Tony Cook knew the test would crash the Perl interpreter, knew the crash was a heap write past the end of a SvGROW allocation, and shipped the test alongside the fix so the fix's correctness would be the test's pass.
The fix commit, four minutes later in the same author's session, removes the TODO marker:
- local $::TODO = "This crashes";That is the smallest, most honest summary of what changed: the maintainer agreed that the test now passes, because the second arithmetic site is now guarded the way the first one was.
32-bit is the precondition, and 32-bit is still shipped
Two facts about the precondition.
First: SSize_t is the signed companion to size_t. On a build where sizeof(void*) == 4, SSize_t_MAX == 2**31 - 1. On a build where sizeof(void*) == 8, SSize_t_MAX == 2**63 - 1. The PoC chooses numbers that overflow the first and don't come close to the second. A 64-bit perl will ask the allocator for four gigabytes, fail the allocation if memory pressure refuses, and survive. A 32-bit perl miscomputes the size and writes through the resulting tiny buffer.
Second: 32-bit Perl is still shipped. Strawberry Perl distributes a 32-bit Windows binary alongside the 64-bit one. ActiveState distributes a 32-bit installer. Most embedded Linux ships a 32-bit userspace. Every router, smart speaker, NAS appliance, and industrial controller running an MIPS or ARMv7 busybox-style distribution is running a 32-bit Perl if it runs Perl at all. The CVE applies to those builds. The CVE does not apply to the laptop in front of most of the people reading the disclosure.
The vendor advisory's mitigation, "avoid compiling untrusted regular expressions on 32-bit Perl builds until patched," is correct and underspecifies the population. The population is every device whose firmware bundled a 32-bit Perl years ago and has not been rebuilt since.
The function still doesn't have the invariant
The patch closes the second arithmetic site. It does not close the bug class in the function.
Twenty-two lines after the new guard, the same code path computes:
data->last_end += l * (mincount - 1);Another mincount * l. The patch leaves it untouched, on the assumption that the new FAIL fires before execution reaches it. The assumption is correct in the current control flow. It is also structural rather than enforced. regcomp_study.c does not have an invariant that says "every multiplication of attacker-controlled mincount against an attacker-controlled byte length must be checked against SSize_t_MAX first." It has two guarded sites now, where it had one before, and at least one further site that is guarded only by virtue of running after the second guard.
This is design-debt-driver in the small. Perl's regex compiler accepts user-supplied repetition counts and multiplies them against per-element lengths to size buffers. Every such multiplication is an overflow surface. Closing the surface site by site as researchers find them is the only mode the code is in. Eighteen days from report to fix for this one. The next one resurfaces when the next researcher fuzzes the next arithmetic.
The surrounding commits to blead from the same author in the same month read:
e4f6817 Storable.xs: Avoid signed int overflow when unpacking a list of hook data items
40754ed pp_pack.c: Avoid some other potential overflows when calculating sizes
5f7eb6b pp_pack.c: Avoid ssize_t overflow when calculating the size of a structure
5e7f119 perl/perl-security#147: test against the actual character lengthsFour arithmetic-overflow fixes in May 2026, across three subsystems, all signed-integer multiplication of user-supplied counts against per-element sizes. Different files, different functions, same class. The class is wherever a parser accepts a length-times-size arithmetic at the surface and the runtime has to materialize the product into a buffer. Perl exposes that at {n} quantifiers, [N] pack counts, and frame counts in Storable hooks. Three subsystems for the same arithmetic, fixed once per arithmetic site.
The arithmetic was guarded. The function was not.