Skip to content

Commit

Permalink
Fix incorrect auto-possessification at end of variable length lookbehind
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipHazel committed Dec 1, 2023
1 parent 8e83acc commit 0820852
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/pcre2_auto_possess.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ matches to an empty string (also represented by a non-zero value). */

for(;;)
{
PCRE2_SPTR bracode;

/* All operations move the code pointer forward.
Therefore infinite recursions are not possible. */

Expand Down Expand Up @@ -616,8 +618,9 @@ for(;;)
so its last iterator can never be possessified if the pattern contains
recursions. (This could be improved by keeping a list of group numbers that
are called by recursion.) */

switch(*(code - GET(code, 1)))

bracode = code - GET(code, 1);
switch(*bracode)
{
case OP_CBRA:
case OP_SCBRA:
Expand All @@ -636,16 +639,19 @@ for(;;)
break;

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

case OP_ASSERT:
case OP_ASSERT_NOT:
case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
case OP_ONCE:
return !entered_a_group;

case OP_ASSERTBACK:
case OP_ASSERTBACK_NOT:
return (bracode[1+LINK_SIZE] == OP_VREVERSE)? FALSE : !entered_a_group;

/* Non-atomic assertions - don't possessify last iterator. This needs
more thought. */

Expand Down
3 changes: 3 additions & 0 deletions testdata/testinput1
Original file line number Diff line number Diff line change
Expand Up @@ -6651,4 +6651,7 @@ $/x
/^..A(*SKIP)B|C/
12ADC

/(?<!a?)/
a

# End of testinput1
4 changes: 4 additions & 0 deletions testdata/testoutput1
Original file line number Diff line number Diff line change
Expand Up @@ -10499,4 +10499,8 @@ No match
12ADC
0: C

/(?<!a?)/
a
No match

# End of testinput1

0 comments on commit 0820852

Please sign in to comment.