Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when attempting to compare selection endpoints with UIA #5309

Closed
codeofdusk opened this issue Apr 10, 2020 · 15 comments · Fixed by #5399
Closed

Crash when attempting to compare selection endpoints with UIA #5309

codeofdusk opened this issue Apr 10, 2020 · 15 comments · Fixed by #5399
Assignees
Labels
Area-Accessibility Issues related to accessibility Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Conhost For issues in the Console codebase Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@codeofdusk
Copy link
Contributor

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd] 21H1 (19603.1000)
Windows Terminal version (if applicable): inbox console

Any other software? NVDA 2020.2

Steps to reproduce

  1. Start the latest NVDA alpha snapshot.
  2. In NVDA advanced settings, enable "use UI Automation to access the Windows Console when available".
  3. Open cmd.
  4. Ssh to an Ubuntu 18.04 system.
  5. Run sudo do-release-upgrade -d.

Expected behavior

NVDA reads the output, and the console remains functional.

Actual behavior

Windows Console crashes, and the following is written to the NVDA log:

ERROR - eventHandler.executeEvent (04:42:19.980) - MainThread (21752):
error executing event: caret on <NVDAObjects.Dynamic_WinConsoleUIAEditableTextWithAutoSelectDetectionUIA object at 0x070733B0> with extra args of {}
Traceback (most recent call last):
  File "eventHandler.pyc", line 155, in executeEvent
  File "eventHandler.pyc", line 92, in __init__
  File "eventHandler.pyc", line 100, in next
  File "NVDAObjects\behaviors.pyc", line 191, in event_caret
  File "editableText.pyc", line 333, in detectPossibleSelectionChange
  File "editableText.pyc", line 340, in _updateSelectionAnchor
  File "NVDAObjects\UIA\__init__.pyc", line 776, in compareEndPoints
  File "comtypesMonkeyPatches.pyc", line 26, in __call__
_ctypes.COMError: (-2147418113, 'Catastrophic failure', (None, None, None, 0, None))

Context

NVDA uses cursor changed events to detect and report selection changes to the user. It receives a cursor change event and compares the previous and current selection endpoints, which causes console to crash in this case. Is there anything I can do to help trace this on the console side?

Please push the fix for this issue to 21H1 as we'd really like to use UIA in console (especially after the excellent work in #4018 and #4495)!

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Apr 10, 2020
@codeofdusk
Copy link
Contributor Author

Cc @carlos-zamora @DHowett-MSFT.

@codeofdusk
Copy link
Contributor Author

For whatever it's worth, this doesn't crash Windows Terminal.

@zadjii-msft zadjii-msft added Area-Accessibility Issues related to accessibility Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. labels Apr 10, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Apr 10, 2020
@zadjii-msft zadjii-msft added Product-Conhost For issues in the Console codebase and removed Product-Terminal The new Windows Terminal. labels Apr 10, 2020
@zadjii-msft zadjii-msft added this to the 21H1 milestone Apr 10, 2020
@zadjii-msft
Copy link
Member

(tentatively throwing this in the 21H1 milestone, but that's totally arbitrary. I figured this is a conhost bug, not a Terminal bug, so that's where it belongs. The team can overrule me ☺️ )

@DHowett-MSFT
Copy link
Contributor

Thanks! Marking it triaged. @carlos-zamora ACK if you've seen it.

@DHowett-MSFT DHowett-MSFT removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Apr 10, 2020
@carlos-zamora
Copy link
Member

Yep! I was taking a look at it a bit today. This one is kind of surprising.

@codeofdusk
Copy link
Contributor Author

Running nano also causes the crash.

@carlos-zamora
Copy link
Member

Took a closer look at this today. It looks like the root cause is that when we switch over to the alt buffer, we are now in a state where the buffer size may have changed. So when you compare a COORD 'A' from the main buffer to another COORD 'B' from the alt buffer, 'A' may not fit in the alt buffer. This makes the comparison invalid, but a crash on our end is definitely not right.

@DHowett-MSFT suggested that we track which buffer the UiaTextRange came from. Then, when two UiaTextRanges are compared, we first ensure that they came from the same buffer.

We could probably return a relevant HRESULT instead. @codeofdusk is there anything you've seen in other apps that you can expect here?

@codeofdusk
Copy link
Contributor Author

What do you mean by the alt buffer? If the console is switching buffers, this also might explain some issues I've been seeing with GetVisibleRanges that I haven't been able to consistently reproduce.

@DHowett-MSFT
Copy link
Contributor

To ask more succinctly: how do we respond to say "this comparison is simply invalid. it takes place in two different coordinate systems."?

The alt buffer is a different "screen mode" for terminal applications. It hides whatever was on the screen prior and lets the application have its own sandbox. Once the application is done, it will turn off the alt buffer, permanently destroying its contents.

@codeofdusk
Copy link
Contributor Author

To ask more succinctly: how do we respond to say "this comparison is simply invalid. it takes place in two different coordinate systems."?

The alt buffer is a different "screen mode" for terminal applications. It hides whatever was on the screen prior and lets the application have its own sandbox. Once the application is done, it will turn off the alt buffer, permanently destroying its contents.

Cc @michaelDCurran.

@codeofdusk
Copy link
Contributor Author

Also cc @LeonarddeR (author of nvaccess/nvda#9660). Could you please provide advice here?

@codeofdusk
Copy link
Contributor Author

codeofdusk commented Apr 17, 2020

Sorry, I'm not familiar enough with UIA to answer. Generally, applications I've seen don't have text ranges that behave like this (i.e. two text ranges from the same text where comparison is incompatible). A crash is definitely not the right thing to do though!

@codeofdusk
Copy link
Contributor Author

For whatever it's worth, it does seem that, when I open a word document, get the text range for the document, open a second document, get that text range, and compare endpoints of the two ranges (from separate documents) it returns null:

>>> ti=nav.makeTextInfo("all") # First document
>>> ti2=nav.makeTextInfo("all") # Second document
>>> ti.compareEndPoints(ti2,"endToStart")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "NVDAObjects\UIA\__init__.pyc", line 776, in compareEndPoints
  File "comtypesMonkeyPatches.pyc", line 26, in __call__
_ctypes.COMError: (-2146233079, None, (None, None, None, 0, None))

@DHowett-MSFT
Copy link
Contributor

Interesting. If that won’t throw off the works, that might be good for us. Ideally, in the long term, we would have different UIA parent objects for the different text buffers.

@ghost ghost added the In-PR This issue has a related PR label Apr 17, 2020
@ghost ghost closed this as completed in #5399 Apr 21, 2020
ghost pushed a commit that referenced this issue Apr 21, 2020
## Summary of the Pull Request
This is a quick-and-easy solution to #5309. If the ITextRangeProvider API allows us to take in two UiaTextRanges, we need to verify that they are both valid.

With this PR, we make sure they both fit in the current TextBuffer. If not, we return `E_FAIL`. Though this doesn't prove that both UiaTextRanges are from the same TextBuffer, at the very least we don't crash and in cases where we can't make a valid comparison, we return an HRESULT failure.

## References
#5406 - This should be the proper solution to this problem. Each UiaTextRange needs to be aware of which TextBuffer it came from.

## PR Checklist
* [X] Closes #5309

## Validation Steps Performed
1. generate enough output to cause the terminal to scroll
2. execute `nano` to make us go into the alternate buffer
This previously crashed, now NVDA seems to detect that there was an error and keeps moving along.
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Apr 21, 2020
@ghost
Copy link

ghost commented May 5, 2020

🎉This issue was addressed in #5399, which has now been successfully released as Windows Terminal Release Candidate v0.11.1251.0 (1.0rc1).:tada:

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Accessibility Issues related to accessibility Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Conhost For issues in the Console codebase Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants