Terminal crashes when starting nano in bash when screen reader is enabled #17582

Closed
opened 2026-01-31 05:46:37 +00:00 by claunia · 8 comments
Owner

Originally created by @LeonarddeR on GitHub (May 26, 2022).

Originally assigned to: @carlos-zamora on GitHub.

Windows Terminal version

1.14.1433.0 preview

Windows build number

22621.1

Other Software

  • Nano in either WSL or ssh
  • Narrator or NVDA 2022.1

Steps to reproduce

  1. Start wsl from the terminal
  2. Type nano test

Expected Behavior

Nano opens as expected

Actual Behavior

WT crashes

Originally created by @LeonarddeR on GitHub (May 26, 2022). Originally assigned to: @carlos-zamora on GitHub. ### Windows Terminal version 1.14.1433.0 preview ### Windows build number 22621.1 ### Other Software * Nano in either WSL or ssh * Narrator or NVDA 2022.1 ### Steps to reproduce 1. Start wsl from the terminal 2. Type `nano test` ### Expected Behavior Nano opens as expected ### Actual Behavior WT crashes
Author
Owner

@LeonarddeR commented on GitHub (May 26, 2022):

Cc @codeofdusk, can you reproduce this?

@LeonarddeR commented on GitHub (May 26, 2022): Cc @codeofdusk, can you reproduce this?
Author
Owner

@codeofdusk commented on GitHub (May 26, 2022):

I wonder if #12561 is related?

CC @carlos-zamora, @zadjii-msft.

@codeofdusk commented on GitHub (May 26, 2022): I wonder if #12561 is related? CC @carlos-zamora, @zadjii-msft.
Author
Owner

@j4james commented on GitHub (May 26, 2022):

FYI, I can reproduce this in vim too. It's another example of a FAIL_FAST crash in Viewport::CompareInBounds - same as #8730. I know we need to track down the source of the incorrect coordinates as well, but can we please, please, please get rid of those FAIL_FAST calls.

@j4james commented on GitHub (May 26, 2022): FYI, I can reproduce this in vim too. It's another example of a `FAIL_FAST` crash in `Viewport::CompareInBounds` - same as #8730. I know we need to track down the source of the incorrect coordinates as well, but can we please, please, please get rid of those `FAIL_FAST` calls.
Author
Owner

@j4james commented on GitHub (May 26, 2022):

As far as I can see, the value that's out of range is coming from the _getDocumentEnd call, and the reason that's out of range is because GetLastNonSpaceCharacter is wrong. The reason that is wrong, is because the viewport passed to it from _getOptimizedBufferSize is wrong. And the reason that is wrong, is because GetTextBufferEndPosition is wrong. GetTextBufferEndPosition gets its Y coordinate from ViewEndIndex, and when we're in the alt buffer, that returns the buffer height, when it should be the height minus one (I believe it's meant to be the index of the last line).

In short, we need to change the value in Terminal::ViewEndIndex to _altBufferSize.height-1. See here:
bf41a90ad8/src/cascadia/TerminalCore/Terminal.cpp (L986-L989)

That said, the original alt buffer implementation (PR #12561) actually had this correct. It was in PR #12719 that it was essentially changed from height-1 to height. If that was an intentional change, the fix may be more complicated that it first appears.

@j4james commented on GitHub (May 26, 2022): As far as I can see, the value that's out of range is coming from the `_getDocumentEnd` call, and the reason that's out of range is because `GetLastNonSpaceCharacter` is wrong. The reason that is wrong, is because the viewport passed to it from `_getOptimizedBufferSize` is wrong. And the reason that is wrong, is because `GetTextBufferEndPosition` is wrong. `GetTextBufferEndPosition` gets its Y coordinate from `ViewEndIndex`, and when we're in the alt buffer, that returns the buffer height, when it should be the height minus one (I believe it's meant to be the index of the last line). In short, we need to change the value in `Terminal::ViewEndIndex` to `_altBufferSize.height-1`. See here: https://github.com/microsoft/terminal/blob/bf41a90ad8cb596c4adae7565b0e6bcf917fc34e/src/cascadia/TerminalCore/Terminal.cpp#L986-L989 That said, the original alt buffer implementation (PR #12561) actually had this correct. It was in PR #12719 that it was essentially changed from `height-1` to `height`. If that was an intentional change, the fix may be more complicated that it first appears.
Author
Owner

@zadjii-msft commented on GitHub (May 26, 2022):

If that was an intentional change, the fix may be more complicated that it first appears.

I really doubt it was. This one's on me I suppose. Thanks for the initial investigation!

@zadjii-msft commented on GitHub (May 26, 2022): > If that was an intentional change, the fix may be more complicated that it first appears. I really doubt it was. This one's on me I suppose. Thanks for the initial investigation!
Author
Owner

@zadjii-msft commented on GitHub (May 26, 2022):

note before lunch: after replacing that with a height-1, there's still a crash after moving the cursor down some rows.

 	Microsoft.Terminal.Control.dll!wil::details::in1diag5::FailFast_If(void * callerReturnAddress, unsigned int lineNumber, const char * fileName, const char * functionName, const char * code, bool condition) Line 5435	C++
 	Microsoft.Terminal.Control.dll!Microsoft::Console::Types::Viewport::CompareInBounds(const _COORD & first, const _COORD & second, bool allowEndExclusive) Line 369	C++
>	Microsoft.Terminal.Control.dll!Microsoft::Console::Types::UiaTextRangeBase::_expandToEnclosingUnit(TextUnit unit) Line 296	C++
 	Microsoft.Terminal.Control.dll!Microsoft::Console::Types::UiaTextRangeBase::ExpandToEnclosingUnit(TextUnit unit) Line 273	C++
 	Microsoft.Terminal.Control.dll!winrt::Microsoft::Terminal::Control::implementation::XamlUiaTextRange::ExpandToEnclosingUnit(winrt::Windows::UI::Xaml::Automation::Text::TextUnit unit) Line 67	C++
  Name Value Type
▶ _start {56,167} _COORD
▶ bufferSize {LT(0, 0) RB(79, 22) [80 x 23]} Microsoft::Console::Types::Viewport
▶ documentEnd {x=0 X=0 y=23 ...} til::point
@zadjii-msft commented on GitHub (May 26, 2022): note before lunch: after replacing that with a `height-1`, there's still a crash after moving the cursor down some rows. ``` Microsoft.Terminal.Control.dll!wil::details::in1diag5::FailFast_If(void * callerReturnAddress, unsigned int lineNumber, const char * fileName, const char * functionName, const char * code, bool condition) Line 5435 C++ Microsoft.Terminal.Control.dll!Microsoft::Console::Types::Viewport::CompareInBounds(const _COORD & first, const _COORD & second, bool allowEndExclusive) Line 369 C++ > Microsoft.Terminal.Control.dll!Microsoft::Console::Types::UiaTextRangeBase::_expandToEnclosingUnit(TextUnit unit) Line 296 C++ Microsoft.Terminal.Control.dll!Microsoft::Console::Types::UiaTextRangeBase::ExpandToEnclosingUnit(TextUnit unit) Line 273 C++ Microsoft.Terminal.Control.dll!winrt::Microsoft::Terminal::Control::implementation::XamlUiaTextRange::ExpandToEnclosingUnit(winrt::Windows::UI::Xaml::Automation::Text::TextUnit unit) Line 67 C++ ```   | Name | Value | Type -- | -- | -- | -- ▶ | _start | {56,167} | _COORD ▶ | bufferSize | {LT(0, 0) RB(79, 22) [80 x 23]} | Microsoft::Console::Types::Viewport ▶ | documentEnd | {x=0 X=0 y=23 ...} | til::point
Author
Owner

@ghost commented on GitHub (Jul 6, 2022):

:tada:This issue was addressed in #13250, which has now been successfully released as Windows Terminal v1.14.186.🎉

Handy links:

@ghost commented on GitHub (Jul 6, 2022): :tada:This issue was addressed in #13250, which has now been successfully released as `Windows Terminal v1.14.186`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.14.186) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Author
Owner

@ghost commented on GitHub (Jul 6, 2022):

:tada:This issue was addressed in #13250, which has now been successfully released as Windows Terminal Preview v1.15.186.🎉

Handy links:

@ghost commented on GitHub (Jul 6, 2022): :tada:This issue was addressed in #13250, which has now been successfully released as `Windows Terminal Preview v1.15.186`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.15.186) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17582