Change information
Commit message:
TextIterator: Fix a crash in substr()
The TextIterator could crash in String::substr() when
TextIteratorBehavior::EmitsOriginalText() was enabled and the layout
object was a LayoutTextFragment.
Specifically, LayoutTextFragment::OriginalText() can return a truncated
string, for example, when handling '::first-letter' pseudo-elements.
However, the unit.DOMStart() and unit.DOMEnd() values typically refer to
the full original text of the fragment. Attempting to call substr() on a
potentially truncated OriginalText() using these full-range DOM offsets
could lead to an out-of-bounds access and a crash.
To fix this, when EmitsOriginalText() is true and layout_text is
identified as a LayoutTextFragment, we now retrieve its complete text
using LayoutTextFragment::CompleteText(). This ensures that substr()
operates on the full string matching the DOM offsets, thereby preventing
the crash.
Bug: 500174824, 473854537
Change-Id: Iaf9279d60dcf2af69bcb96dac7c1333f27a214f4
Cr-Commit-Position: refs/heads/main@{#1614313}
Files:
- M third_party/blink/renderer/core/editing/iterators/text_iterator_test.cc
- M third_party/blink/renderer/core/editing/iterators/text_iterator_text_node_handler.cc
Change size: S
Delta: 2 files changed, 20 insertions(+), 2 deletions(-)
Branch: refs/heads/main
Submit Requirements:
Code-Review: +1 by Fredrik Söderquist