Skip to content

Commit f912626

Browse files
author
Karl Williamson
committed
Assertion fails in multi-char regex match
In '"s\N{U+DF}" =~ /\x{00DF}/i, the LHS folds to 'sss', the RHS to 'ss'. The bug occurs when the RHS tries to match the first two es's, but that splits the LHS \xDF character, which Perl doesn't know how to handle, and the assertion got triggered. (This is similar to [perl #72998].) The solution adopted here is to disallow a partial character match, as #72998 did as well.
1 parent 17163f8 commit f912626

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

regexec.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6726,9 +6726,12 @@ S_reginclass(pTHX_ const regexp * const prog, register const regnode * const n,
67266726
STRLEN len;
67276727
const char * const s = SvPV_const(sv, len);
67286728

6729-
if (len <= total_foldlen && memEQ(s,
6730-
(char*)folded,
6731-
len))
6729+
if (len <= total_foldlen
6730+
&& memEQ(s, (char*)folded, len)
6731+
6732+
/* If 0, means matched a partial char. See
6733+
* [perl #90536] */
6734+
&& map_fold_len_back[len])
67326735
{
67336736

67346737
/* Advance the target string ptr to account for
@@ -6737,7 +6740,6 @@ S_reginclass(pTHX_ const regexp * const prog, register const regnode * const n,
67376740
* length. */
67386741
if (lenp) {
67396742
*lenp = map_fold_len_back[len];
6740-
assert(*lenp != 0); /* Otherwise will loop */
67416743
}
67426744
match = TRUE;
67436745
break;

t/re/pat_advanced.t

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,10 @@ EOP
21082108
like("\x{00DF}", qr/[\x{1E9E}_]*/i, "\"\\x{00DF}\" =~ /[\\x{1E9E}_]*/i was looping");
21092109
}
21102110

2111+
{ # Bug #90536, caused failed assertion
2112+
unlike("s\N{U+DF}", qr/^\x{00DF}/i, "\"s\\N{U+DF}\", qr/^\\x{00DF}/i");
2113+
}
2114+
21112115
# !!! NOTE that tests that aren't at all likely to crash perl should go
21122116
# a ways above, above these last ones.
21132117

0 commit comments

Comments
 (0)