Skip to content

Commit

Permalink
Fix braposzero check
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltan Herczeg committed Nov 12, 2023
1 parent fbe045b commit b43e745
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/pcre2_jit_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ typedef struct compiler_common {
sljit_s32 match_end_ptr;
/* Points to the marked string. */
sljit_s32 mark_ptr;
/* Recursive control verb management chain. */
/* Head of the recursive control verb management chain.
Each item must have a previous offset and type
(see control_types) values. See do_search_mark. */
sljit_s32 control_head_ptr;
/* Points to the last matched capture block index. */
sljit_s32 capture_last_ptr;
Expand Down Expand Up @@ -6650,7 +6652,8 @@ GET_LOCAL_BASE(TMP1, 0, 0);
/* Drop frames until we reach STACK_TOP. */
mainloop = LABEL();
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), -SSIZE_OF(sw));
jump = CMP(SLJIT_SIG_LESS_EQUAL, TMP2, 0, SLJIT_IMM, 0);
OP2U(SLJIT_SUB | SLJIT_SET_SIG_LESS_EQUAL | SLJIT_SET_Z, TMP2, 0, SLJIT_IMM, 0);
jump = JUMP(SLJIT_SIG_LESS_EQUAL);

OP2(SLJIT_ADD, TMP2, 0, TMP2, 0, TMP1, 0);
if (HAS_VIRTUAL_REGISTERS)
Expand All @@ -6671,7 +6674,8 @@ else
JUMPTO(SLJIT_JUMP, mainloop);

JUMPHERE(jump);
jump = CMP(SLJIT_NOT_ZERO /* SIG_LESS */, TMP2, 0, SLJIT_IMM, 0);
sljit_set_current_flags(compiler, SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE | SLJIT_SET_SIG_LESS_EQUAL | SLJIT_SET_Z);
jump = JUMP(SLJIT_NOT_ZERO /* SIG_LESS */);
/* End of reverting values. */
OP_SRC(SLJIT_FAST_RETURN, RETURN_ADDR, 0);

Expand Down Expand Up @@ -11244,7 +11248,7 @@ switch(opcode)
case OP_CBRAPOS:
case OP_SCBRAPOS:
offset = GET2(cc, 1 + LINK_SIZE);
/* This case cannot be optimized in the same was as
/* This case cannot be optimized in the same way as
normal capturing brackets. */
SLJIT_ASSERT(common->optimized_cbracket[offset] == 0);
cbraprivptr = OVECTOR_PRIV(offset);
Expand Down Expand Up @@ -13368,12 +13372,19 @@ static SLJIT_INLINE void compile_bracketpos_backtrackingpath(compiler_common *co
DEFINE_COMPILER;
int offset;
struct sljit_jump *jump;
PCRE2_SPTR cc;

/* No retry on backtrack, just drop everything. */
if (CURRENT_AS(bracketpos_backtrack)->framesize < 0)
{
if (*current->cc == OP_CBRAPOS || *current->cc == OP_SCBRAPOS)
cc = current->cc;

if (*cc == OP_BRAPOSZERO)
cc++;

if (*cc == OP_CBRAPOS || *cc == OP_SCBRAPOS)
{
offset = (GET2(current->cc, 1 + LINK_SIZE)) << 1;
offset = (GET2(cc, 1 + LINK_SIZE)) << 1;
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(STACK_TOP), STACK(0));
OP1(SLJIT_MOV, TMP2, 0, SLJIT_MEM1(STACK_TOP), STACK(1));
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), OVECTOR(offset), TMP1, 0);
Expand Down
1 change: 1 addition & 0 deletions src/pcre2_jit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ static struct regression_test_case regression_test_cases[] = {
{ MU, A, 0, 0, "((b*))++m", "bxbbxbbbxbbm" },
{ MU, A, 0, 0, "((b*))*+m", "bxbbxbbbxm" },
{ MU, A, 0, 0, "((b*))*+m", "bxbbxbbbxbbm" },
{ MU, A, 0, 0, "(A)*+$", "ABC" },
{ MU, A, 0, 0 | F_NOMATCH, "(?>(b{2,4}))(?:(?:(aa|c))++m|(?:(aa|c))+n)", "bbaacaaccaaaacxbbbmbn" },
{ MU, A, 0, 0, "((?:b)++a)+(cd)*+m", "bbababbacdcdnbbababbacdcdm" },
{ MU, A, 0, 0, "((?:(b))++a)+((c)d)*+m", "bbababbacdcdnbbababbacdcdm" },
Expand Down

0 comments on commit b43e745

Please sign in to comment.