Bug 235348 - [JSC] Fix YarrJIT backtrackCharacterClassNonGreedy breakpoint
Summary: [JSC] Fix YarrJIT backtrackCharacterClassNonGreedy breakpoint
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-01-18 22:51 PST by Yusuke Suzuki
Modified: 2022-01-19 11:53 PST (History)
8 users (show)

See Also:


Attachments
Patch (2.81 KB, patch)
2022-01-18 22:57 PST, Yusuke Suzuki
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2022-01-18 22:51:23 PST
[JSC] Fix YarrJIT backtrackCharacterClassNonGreedy breakpoint
Comment 1 Yusuke Suzuki 2022-01-18 22:57:59 PST
Created attachment 449465 [details]
Patch
Comment 2 Yusuke Suzuki 2022-01-18 22:58:18 PST
rdar://84108897
Comment 3 Darin Adler 2022-01-19 08:53:13 PST
Comment on attachment 449465 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=449465&action=review

> Source/JavaScriptCore/yarr/YarrJIT.cpp:2062
> +            m_jit.sub32(MacroAssembler::TrustedImm32(1), m_regs.index);

Do we need anything different in the m_decodeSurrogatePairs case? In that case it might be incremented my more than one?
Comment 4 Yusuke Suzuki 2022-01-19 09:37:09 PST
Comment on attachment 449465 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=449465&action=review

>> Source/JavaScriptCore/yarr/YarrJIT.cpp:2062
>> +            m_jit.sub32(MacroAssembler::TrustedImm32(1), m_regs.index);
> 
> Do we need anything different in the m_decodeSurrogatePairs case? In that case it might be incremented my more than one?

nonGreedyFailuresDecrementIndex is added only when m_decodeSurrogatePairs is true. So, this path will be taken only when m_decodeSurrogatePairs is true case. (nonGreedyFailuresDecrementIndex is added in L2052, which is executed when m_decodeSurrogatePairs is true).
Comment 5 Darin Adler 2022-01-19 09:46:00 PST
Comment on attachment 449465 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=449465&action=review

>>> Source/JavaScriptCore/yarr/YarrJIT.cpp:2062
>>> +            m_jit.sub32(MacroAssembler::TrustedImm32(1), m_regs.index);
>> 
>> Do we need anything different in the m_decodeSurrogatePairs case? In that case it might be incremented my more than one?
> 
> nonGreedyFailuresDecrementIndex is added only when m_decodeSurrogatePairs is true. So, this path will be taken only when m_decodeSurrogatePairs is true case. (nonGreedyFailuresDecrementIndex is added in L2052, which is executed when m_decodeSurrogatePairs is true).

OK, maybe I can’t review then, because I can’t spot the add32 that this subtract is reversing, so I suppose you need a review from a subject matter expert. Sorry, I was hoping I could save a little time by being your reviewer!
Comment 6 Yusuke Suzuki 2022-01-19 10:39:20 PST
Comment on attachment 449465 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=449465&action=review

>>>> Source/JavaScriptCore/yarr/YarrJIT.cpp:2062
>>>> +            m_jit.sub32(MacroAssembler::TrustedImm32(1), m_regs.index);
>>> 
>>> Do we need anything different in the m_decodeSurrogatePairs case? In that case it might be incremented my more than one?
>> 
>> nonGreedyFailuresDecrementIndex is added only when m_decodeSurrogatePairs is true. So, this path will be taken only when m_decodeSurrogatePairs is true case. (nonGreedyFailuresDecrementIndex is added in L2052, which is executed when m_decodeSurrogatePairs is true).
> 
> OK, maybe I can’t review then, because I can’t spot the add32 that this subtract is reversing, so I suppose you need a review from a subject matter expert. Sorry, I was hoping I could save a little time by being your reviewer!

np!!!!! Thank you for your review :D
Comment 7 Michael Saboff 2022-01-19 11:22:46 PST
Comment on attachment 449465 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=449465&action=review

r=me

>>>>> Source/JavaScriptCore/yarr/YarrJIT.cpp:2062
>>>>> +            m_jit.sub32(MacroAssembler::TrustedImm32(1), m_regs.index);
>>>> 
>>>> Do we need anything different in the m_decodeSurrogatePairs case? In that case it might be incremented my more than one?
>>> 
>>> nonGreedyFailuresDecrementIndex is added only when m_decodeSurrogatePairs is true. So, this path will be taken only when m_decodeSurrogatePairs is true case. (nonGreedyFailuresDecrementIndex is added in L2052, which is executed when m_decodeSurrogatePairs is true).
>> 
>> OK, maybe I can’t review then, because I can’t spot the add32 that this subtract is reversing, so I suppose you need a review from a subject matter expert. Sorry, I was hoping I could save a little time by being your reviewer!
> 
> np!!!!! Thank you for your review :D

This is safe and appropriate because we only get in this case when the following is true (from reading L2050-2063 and L516-520):
 1) We are in the m_decodeSurrogatePairs case.
 2) We are trying to match a non-BMP character.
 3) We are at the end of the string input with the first of the two characters, i.e. we have incremented 1.
 4) There we can't advance the index for the second character we can't read.
Therefore we need to decrement index by 1 and fall through to the failed non-greedy match.
Comment 8 Yusuke Suzuki 2022-01-19 11:27:12 PST
Comment on attachment 449465 [details]
Patch

Thanks!
Comment 9 EWS 2022-01-19 11:53:50 PST
Committed r288224 (246184@main): <https://commits.webkit.org/246184@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 449465 [details].