Bug 1675172 - Prevent an infinite loop when finding the line end boundary for an offset of 0, r=Jamie

Use a safer looping method, walking forward from aOffset to tmpOffset to prevent wrapping around at 0.

Differential Revision: https://phabricator.services.mozilla.com/D95826
This commit is contained in:
Marco Zehe 2020-11-04 07:09:59 +00:00
Родитель d72d343fad
Коммит 19a10e117a
1 изменённых файлов: 7 добавлений и 6 удалений

Просмотреть файл

@ -819,14 +819,15 @@ uint32_t HyperTextAccessible::FindLineBoundary(
// layout could not find the offset for us. This can happen with certain // layout could not find the offset for us. This can happen with certain
// inline-block elements. // inline-block elements.
if (nextLineBeginOffset <= aOffset) { if (nextLineBeginOffset <= aOffset) {
// Walk back from the tmpOffset to the offset we started from, // Walk forward from the offset we started from up to tmpOffset,
// stopping after a line end character. // stopping after a line end character.
nextLineBeginOffset = tmpOffset; nextLineBeginOffset = aOffset;
while (nextLineBeginOffset >= aOffset && while (nextLineBeginOffset < tmpOffset) {
!IsLineEndCharAt(nextLineBeginOffset - 1)) { if (IsLineEndCharAt(nextLineBeginOffset)) {
nextLineBeginOffset--; return nextLineBeginOffset + 1;
}
nextLineBeginOffset++;
} }
return nextLineBeginOffset;
} }
return nextLineBeginOffset; return nextLineBeginOffset;