Skip to content

Commit

Permalink
Validate cursor position in UIA UTR ctor (#12436)
Browse files Browse the repository at this point in the history
This adds some validation in the `UiaTextRange` ctor for the cursor position.

#8730 was caused by creating a `UiaTextRange` at the cursor position when it was in a delayed state (meaning it's purposefully hanging off of the right edge of the buffer). Normally, `Cursor` maintains a flag to keep track of when that occurs, but Windows Terminal isn't maintaining that properly in `Terminal::WriteBuffer`.

The _correct_ approach would be to fix `WriteBuffer` then leverage that flag for validation in `UiaTextRange`. However, messing with `WriteBuffer` is a little too risky for our comfort right now. So we'll do the second half of that by checking if the cursor position is valid. Since the cursor is really only expected to be out of bounds when it's in that delayed state, we get the same result (just maybe a tad slower than simply checking a flag).

Closes #8730

Filed #12440 to track changes in `Terminal::_WriteBuffer` for delayed EOL wrap.

## Validation Steps Performed
While using magnifier, input/delete wrapped text in input buffer.

(cherry picked from commit 5dcf526)
  • Loading branch information
carlos-zamora authored and DHowett committed Feb 9, 2022
1 parent 2870303 commit 7f660c2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/types/UiaTextRangeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ HRESULT UiaTextRangeBase::RuntimeClassInitialize(_In_ IUiaData* pData,
_In_ std::wstring_view wordDelimiters) noexcept
try
{
RETURN_HR_IF_NULL(E_INVALIDARG, pData);
RETURN_IF_FAILED(RuntimeClassInitialize(pData, pProvider, wordDelimiters));

// GH#8730: The cursor position may be in a delayed state, resulting in it being out of bounds.
// If that's the case, clamp it to be within bounds.
// TODO GH#12440: We should be able to just check some fields off of the Cursor object,
// but Windows Terminal isn't updating those flags properly.
_start = cursor.GetPosition();
pData->GetTextBuffer().GetSize().Clamp(_start);
_end = _start;

UiaTracing::TextRange::Constructor(*this);
Expand Down

0 comments on commit 7f660c2

Please sign in to comment.