[Webkit-unassigned] [Bug 231606] ASSERT hit in surrogatePairAwareIndex and surrogatePairAwareStart lambdas for text with unpaired surrogates

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Oct 13 15:41:46 PDT 2021


https://bugs.webkit.org/show_bug.cgi?id=231606

--- Comment #17 from Gabriel Nava Marino <gnavamarino at apple.com> ---
(In reply to Darin Adler from comment #15)
> Comment on attachment 440982 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=440982&action=review
> 
> >>>> Source/WebCore/layout/formattingContexts/inline/text/TextUtil.cpp:155
> >>>>  
> >>> 
> >>> It would be:
> >>> 
> >>>     auto right = std::min<unsigned>(left + offset, (startPosition + length - 1));
> >>>     U16_SET_CP_LIMIT(text, 0, right, text.length());
> >>> 
> >>>     auto middle = surrogatePairAwareIndex((left + right) / 2);
> >>>     U16_SET_CP_LIMIT(text, 0, middle, text.length());
> >> 
> >> Thank you, I will try this! Although I just notice that currently, surrogatePairAwareIndex returns the index at trail whereas U16_SET_CP_LIMIT returns the index past it:
> >> 
> >> #define U16_SET_CP_LIMIT(s, start, i, length) UPRV_BLOCK_MACRO_BEGIN { \
> >>     if((start)<(i) && ((i)<(length) || (length)<0) && U16_IS_LEAD((s)[(i)-1]) && U16_IS_TRAIL((s)[i])) { \
> >>         ++(i); \
> >>     } \
> >> } UPRV_BLOCK_MACRO_END
> > 
> > Oh, OK, good point. So my code is wrong. It would be more like this:
> > 
> >     auto right = std::min<unsigned>(left + offset + 1, startPosition + length);
> >     U16_SET_CP_LIMIT(text, 0, right, text.length());
> >     --right;
> 
> And perhaps then could change the logic to get rid of the need for the
> "--right".

I tried adjusting the logic so that we could get rid of the need for the "--right". However, because of the loop condition "while (left < right)" and need for two U16_SET_CP_LIMIT calls and then the subsequent U16_SET_CP_START, we would need at least one "--right" after U16_SET_CP_START.

To avoid this, I have opted to keep surrogatePairAwareIndex and return index - 1 instead. Although we are still using this lambda, it is only using the U16 U16_SET_CP_LIMIT macro now.

> 
> Maybe a waste of time, but I do think that using the U16 macros is still a
> little easier to get correct than writing our own code.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20211013/2ec61945/attachment.htm>


More information about the webkit-unassigned mailing list