-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
v2 conhost crash with SetConsoleScreenBufferInfoEx calls #256
Comments
Thanks for the bug report, I've filed msft:19013486 to make sure this gets fixed ASAP :) |
I'm not able to reproduce this issue anymore. Perhaps we fixed it? If it's still crashing for you, can you try to find the report ID so I can maybe correlate it? I believe it's Event ID 1000 for Application Error (and should contain conhost.exe as the faulting application path with a report ID GUID that you can give to me). |
Closing this for now. If you can get the report ID from a recent repro of this crash, we'd love to take a look. Thanks! |
This fixes a number of exceptions that can cause conhost to crash when the buffer is resized in such a way that the viewport or cursor position end up out of bounds. Technically this is a fix for issue #256, although that has been closed as "needs-repro". The main fix was to add checks in the `SetConsoleScreenBufferSizeImpl` and `SetConsoleScreenBufferInfoExImpl` methods, to make sure the viewport doesn't extend past the bottom or right of the buffer after a resize. If it has overflowed, we move the viewport back up or left until it's back within the buffer boundaries. We also check if the cursor position has ended up out of bounds, and if so, clamp it back inside the buffer. The `SCREEN_INFORMATION::SetViewport` was also a source of viewport overflow problems, because it was mistakenly using inclusive coordinates in its range checks, which resulted in them being off by one. That has now been corrected to use exclusive coordinates. Finally, the `IsCursorDoubleWidth` method was incorrectly marked as `noexcept`, which was preventing its exceptions from being caught. Ideally it shouldn't be throwing exceptions at all any more, but I've removed the `noexcept` specifier, so if it does throw an exception, it'll at least have more chance of recovering without a crash. ## Validation Steps Performed I put together a few test cases (based on the reports in issues #276 and #1976) which consistently caused conhost to crash, or to generate an exception visible in the debug output. With this PR applied, those test cases are no longer crashing or triggering exceptions. Closes #1976
This fixes a number of exceptions that can cause conhost to crash when the buffer is resized in such a way that the viewport or cursor position end up out of bounds. Technically this is a fix for issue #256, although that has been closed as "needs-repro". The main fix was to add checks in the `SetConsoleScreenBufferSizeImpl` and `SetConsoleScreenBufferInfoExImpl` methods, to make sure the viewport doesn't extend past the bottom or right of the buffer after a resize. If it has overflowed, we move the viewport back up or left until it's back within the buffer boundaries. We also check if the cursor position has ended up out of bounds, and if so, clamp it back inside the buffer. The `SCREEN_INFORMATION::SetViewport` was also a source of viewport overflow problems, because it was mistakenly using inclusive coordinates in its range checks, which resulted in them being off by one. That has now been corrected to use exclusive coordinates. Finally, the `IsCursorDoubleWidth` method was incorrectly marked as `noexcept`, which was preventing its exceptions from being caught. Ideally it shouldn't be throwing exceptions at all any more, but I've removed the `noexcept` specifier, so if it does throw an exception, it'll at least have more chance of recovering without a crash. ## Validation Steps Performed I put together a few test cases (based on the reports in issues #276 and #1976) which consistently caused conhost to crash, or to generate an exception visible in the debug output. With this PR applied, those test cases are no longer crashing or triggering exceptions. Closes #1976 (cherry picked from commit 9a07049)
What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)
Using
SetConsoleScreenBufferInfoEx
to make the console buffer and window smaller, simultaneously, can crash the v2 conhost with a recent Insiders build.Steps:
What's wrong / what should be happening instead:
SetConsoleScreenBufferInfoEx
shouldn't crash. The textHello?
should appear, and the console should return control to cmd/powershell.Aside 1: I don't think this affects winpty at all.
Aside 2:
SetConsoleScreenBufferInfoEx
seems to handlesrWindow
differently than bothSetConsoleWindowInfo
andGetConsoleScreenBufferInfoEx
. It tends to set the window size to 1 less width/height than the requested size, so a pair of calls toGetConsoleScreenBufferInfoEx
andSetConsoleScreenBufferInfoEx
shrinks the console window.Test program
The text was updated successfully, but these errors were encountered: