mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibRegex: Check backreference index before looking it up
If a backref happens after it's cleared, the slot may be cleared already.
This commit is contained in:
parent
e695dc1405
commit
299b9ca572
Notes:
github-actions[bot]
2025-04-06 18:22:15 +00:00
Author: https://github.com/alimpfard
Commit: 299b9ca572
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4246
2 changed files with 5 additions and 0 deletions
|
@ -585,6 +585,9 @@ ALWAYS_INLINE ExecutionResult OpCode_Compare::execute(MatchInput const& input, M
|
||||||
}
|
}
|
||||||
case CharacterCompareType::Reference: {
|
case CharacterCompareType::Reference: {
|
||||||
auto reference_number = (size_t)m_bytecode->at(offset++);
|
auto reference_number = (size_t)m_bytecode->at(offset++);
|
||||||
|
if (input.match_index >= state.capture_group_matches.size())
|
||||||
|
return ExecutionResult::Failed_ExecuteLowPrioForks;
|
||||||
|
|
||||||
auto& groups = state.capture_group_matches.at(input.match_index);
|
auto& groups = state.capture_group_matches.at(input.match_index);
|
||||||
if (groups.size() <= reference_number)
|
if (groups.size() <= reference_number)
|
||||||
return ExecutionResult::Failed_ExecuteLowPrioForks;
|
return ExecutionResult::Failed_ExecuteLowPrioForks;
|
||||||
|
|
|
@ -741,6 +741,8 @@ TEST_CASE(ECMA262_match)
|
||||||
// Tests nested lookahead with alternation - verifies proper save/restore stack cleanup
|
// Tests nested lookahead with alternation - verifies proper save/restore stack cleanup
|
||||||
{ "a(?=.(?=c)|b)b"sv, "ab"sv, true },
|
{ "a(?=.(?=c)|b)b"sv, "ab"sv, true },
|
||||||
{ "(?=)(?=\\d)"sv, "smart"sv, false },
|
{ "(?=)(?=\\d)"sv, "smart"sv, false },
|
||||||
|
// Backrefs are cleared after lookaheads, the indices should be checked before lookup.
|
||||||
|
{ "(?!(b))\\1"sv, "a"sv, false },
|
||||||
};
|
};
|
||||||
|
|
||||||
for (auto& test : tests) {
|
for (auto& test : tests) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue