Bug 239909 - CrashTracer: com.apple.WebKit.WebContent at com.apple.WebKit: WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions
Summary: CrashTracer: com.apple.WebKit.WebContent at com.apple.WebKit: WebKit::TextChe...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Devin Rousso
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-04-29 13:23 PDT by Devin Rousso
Modified: 2022-05-27 14:51 PDT (History)
12 users (show)

See Also:


Attachments
Patch (6.96 KB, patch)
2022-04-29 13:36 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (17.23 KB, patch)
2022-05-16 17:27 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff
Patch (17.23 KB, patch)
2022-05-16 20:04 PDT, Devin Rousso
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Devin Rousso 2022-04-29 13:23:04 PDT
an `NSRangeException` is thrown inside `-[NSConcreteMutableAttributedString addAttribute:value:range:]`
Comment 1 Devin Rousso 2022-04-29 13:23:23 PDT
<rdar://problem/87885717>
Comment 2 Devin Rousso 2022-04-29 13:36:05 PDT
Created attachment 458605 [details]
Patch
Comment 3 Alexey Proskuryakov 2022-04-29 14:20:25 PDT
Comment on attachment 458605 [details]
Patch

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

> Source/WebCore/ChangeLog:3
> +        CrashTracer: com.apple.WebKit.WebContent at com.apple.WebKit: WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions

A subtle TextIterator fix like this seems like it strongly requires a regression test.
Comment 4 Devin Rousso 2022-04-29 14:29:21 PDT
Comment on attachment 458605 [details]
Patch

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

>> Source/WebCore/ChangeLog:3
>> +        CrashTracer: com.apple.WebKit.WebContent at com.apple.WebKit: WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions
> 
> A subtle TextIterator fix like this seems like it strongly requires a regression test.

yeah im working on that now

i put this up to let EWS munch on it :)
Comment 5 Darin Adler 2022-04-29 14:53:49 PDT
Comment on attachment 458605 [details]
Patch

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

>>> Source/WebCore/ChangeLog:3
>>> +        CrashTracer: com.apple.WebKit.WebContent at com.apple.WebKit: WebKit::TextCheckingControllerProxy::annotatedSubstringBetweenPositions
>> 
>> A subtle TextIterator fix like this seems like it strongly requires a regression test.
> 
> yeah im working on that now
> 
> i put this up to let EWS munch on it :)

I think it would be best to have some TextIterator tests for this bug that do *not* involve NSAttributedString; this underlying issue is not specific to the NSAttributedString code path, and can be tested without involving the NSAttributedString code path.

I also think the NSAttributedString code path might benefit from additional defensive range checking rather than relying on the subtle and complex TextIterator machinery to never create something with an incorrect offset.

We may want to fix this bug both ways, with:
a) defensive code in the code that deals with NSAttributedString that would prevent this kind of incorrect text offset computation from causing a crash, and
b) this TextIterator change that gives us a correct result that is valuable in and of itself.

Unfortunately the (b) change would make it a little harder to test (a) since we would no longer be able to use this bug to test the defensive checks are necessary.
Comment 6 Devin Rousso 2022-05-16 17:27:30 PDT
Created attachment 459466 [details]
Patch
Comment 7 Devin Rousso 2022-05-16 17:29:23 PDT
Comment on attachment 459466 [details]
Patch

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

> Source/WebCore/editing/TextIterator.cpp:638
> +            if (runStart >= runEnd && m_behaviors.contains(TextIteratorBehavior::IgnoresWhiteSpaceAtEndOfRun)) {
> +                m_textRun = nextTextRun;
> +                continue;
> +            }

I think this is actually the correct behavior that should _always_ be used, but since this is a regression I'd rather target my fix to just that and then (perhaps) remove the check later on so that if there is a problem, rollouts are less conflicting (i.e. fixes one bug only to introduce another)
Comment 8 Devin Rousso 2022-05-16 20:04:55 PDT
Created attachment 459472 [details]
Patch
Comment 9 Devin Rousso 2022-05-17 11:31:44 PDT
Pull request: https://github.com/WebKit/WebKit/pull/681
Comment 10 EWS 2022-05-27 14:51:15 PDT
Committed r294955 (251061@main): <https://commits.webkit.org/251061@main>

Reviewed commits have been landed. Closing PR #681 and removing active labels.