[TextBoxView] Crash during large selection while background layout is incomplete
Summary
TextBoxView.GetLineIndexFromOffset can fail during large-text selection when layout is still in time-sliced background progress, causing a crash/fail-fast path instead of graceful handling.
Observed behavior
- Selecting text in very large
TextBox content (for example, very long lines / high offsets) can trigger a consistency/assert failure.
- The failure happens when selection/highlight processing requests an offset beyond the currently measured line range.
Repro notes (public)
- Create/open a WPF app view with a
TextBox containing a very large amount of text (for example, one very long line or total offsets in 100K+ range).
- Trigger selection operations while layout is still being processed incrementally (IME/search/focus interactions can increase likelihood).
- Observe crash/fail-fast behavior from
TextBoxView.GetLineIndexFromOffset path.
Impact
- Affects reliability of text editing/selection in large-document scenarios.
- More likely in interactive flows where layout and selection/focus updates interleave.
Expected behavior
Selection/highlight should remain stable and never crash, even when background layout has not measured all lines yet.
Actual behavior
The lookup assumes the requested offset is always inside measured _lineMetrics, and can fail when it is temporarily outside that range.
Suspected root cause
TextBoxView performs time-sliced layout, so _lineMetrics may be only partially populated. During that window, selection/highlight can request an offset greater than the last measured line EndOffset, and the search path fails.
Proposed fix direction
- Add defensive clamping in
GetLineIndexFromOffset for offsets beyond currently measured range.
- Return the last measured line index when background layout is pending.
- Keep correctness checks for unexpected conditions while avoiding crash in expected incremental-layout windows.
- Remove redundant preconditions that incorrectly assume full containment during transitional layout states.
[TextBoxView] Crash during large selection while background layout is incomplete
Summary
TextBoxView.GetLineIndexFromOffsetcan fail during large-text selection when layout is still in time-sliced background progress, causing a crash/fail-fast path instead of graceful handling.Observed behavior
TextBoxcontent (for example, very long lines / high offsets) can trigger a consistency/assert failure.Repro notes (public)
TextBoxcontaining a very large amount of text (for example, one very long line or total offsets in 100K+ range).TextBoxView.GetLineIndexFromOffsetpath.Impact
Expected behavior
Selection/highlight should remain stable and never crash, even when background layout has not measured all lines yet.
Actual behavior
The lookup assumes the requested offset is always inside measured
_lineMetrics, and can fail when it is temporarily outside that range.Suspected root cause
TextBoxViewperforms time-sliced layout, so_lineMetricsmay be only partially populated. During that window, selection/highlight can request an offset greater than the last measured lineEndOffset, and the search path fails.Proposed fix direction
GetLineIndexFromOffsetfor offsets beyond currently measured range.