Skip to content

Commit 0820852

Browse files
committed
Fix incorrect auto-possessification at end of variable length lookbehind
1 parent 8e83acc commit 0820852

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/pcre2_auto_possess.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ matches to an empty string (also represented by a non-zero value). */
560560

561561
for(;;)
562562
{
563+
PCRE2_SPTR bracode;
564+
563565
/* All operations move the code pointer forward.
564566
Therefore infinite recursions are not possible. */
565567

@@ -616,8 +618,9 @@ for(;;)
616618
so its last iterator can never be possessified if the pattern contains
617619
recursions. (This could be improved by keeping a list of group numbers that
618620
are called by recursion.) */
619-
620-
switch(*(code - GET(code, 1)))
621+
622+
bracode = code - GET(code, 1);
623+
switch(*bracode)
621624
{
622625
case OP_CBRA:
623626
case OP_SCBRA:
@@ -636,16 +639,19 @@ for(;;)
636639
break;
637640

638641
/* Atomic sub-patterns and assertions can always auto-possessify their
639-
last iterator. However, if the group was entered as a result of checking
640-
a previous iterator, this is not possible. */
642+
last iterator except for variable length lookbehinds. However, if the
643+
group was entered as a result of checking a previous iterator, this is
644+
not possible. */
641645

642646
case OP_ASSERT:
643647
case OP_ASSERT_NOT:
644-
case OP_ASSERTBACK:
645-
case OP_ASSERTBACK_NOT:
646648
case OP_ONCE:
647649
return !entered_a_group;
648650

651+
case OP_ASSERTBACK:
652+
case OP_ASSERTBACK_NOT:
653+
return (bracode[1+LINK_SIZE] == OP_VREVERSE)? FALSE : !entered_a_group;
654+
649655
/* Non-atomic assertions - don't possessify last iterator. This needs
650656
more thought. */
651657

testdata/testinput1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6651,4 +6651,7 @@ $/x
66516651
/^..A(*SKIP)B|C/
66526652
12ADC
66536653

6654+
/(?<!a?)/
6655+
a
6656+
66546657
# End of testinput1

testdata/testoutput1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10499,4 +10499,8 @@ No match
1049910499
12ADC
1050010500
0: C
1050110501

10502+
/(?<!a?)/
10503+
a
10504+
No match
10505+
1050210506
# End of testinput1

0 commit comments

Comments
 (0)