Crash in ScrollConsoleScreenBuffer when destination coordinates overflow #7324

Closed
opened 2026-01-31 01:01:06 +00:00 by claunia · 5 comments
Owner

Originally created by @j4james on GitHub (Apr 7, 2020).

Originally assigned to: @lhecker on GitHub.

Environment

Windows build number: Version 10.0.18362.657

Steps to reproduce

Compile and run the following C++ code in a conhost cmd shell:

#include <windows.h>

void main() {
    SMALL_RECT rect = {0, 0, 40, 0};
    COORD dest = {32767, 0};
    CHAR_INFO fill = {L'X', 0x07};
    HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
    ScrollConsoleScreenBufferW(output, &rect, NULL, dest, &fill);
}

Expected behavior

The first 40 characters of the first line should fill with X's.

Actual behavior

The console crashes.

When the ScrollRegion function is copying the area that is being scrolled, the _CopyRectangle function makes use of the Viewport::WalkInBoundsCircular method, and that fails when the target position goes out of bounds. See here:

5de9fa9cf3/src/types/viewport.cpp (L411)

Originally created by @j4james on GitHub (Apr 7, 2020). Originally assigned to: @lhecker on GitHub. # Environment Windows build number: Version 10.0.18362.657 # Steps to reproduce Compile and run the following C++ code in a conhost cmd shell: ```cpp #include <windows.h> void main() { SMALL_RECT rect = {0, 0, 40, 0}; COORD dest = {32767, 0}; CHAR_INFO fill = {L'X', 0x07}; HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); ScrollConsoleScreenBufferW(output, &rect, NULL, dest, &fill); } ``` # Expected behavior The first 40 characters of the first line should fill with X's. # Actual behavior The console crashes. When the `ScrollRegion` function is copying the area that is being scrolled, the `_CopyRectangle` function makes use of the `Viewport::WalkInBoundsCircular` method, and that fails when the target position goes out of bounds. See here: https://github.com/microsoft/terminal/blob/5de9fa9cf375e9b5bdc582d8d166604eeb519844/src/types/viewport.cpp#L411
Author
Owner

@j4james commented on GitHub (Apr 7, 2020):

FYI, I've just tested with the first open source release (commit d4d59fa339), and the bug was already present there. However, the legacy console doesn't have this issue.

In some ways this is could be considered a part of issue #4153, but I thought it worth raising separately because of the crash, and the fact that it's not obviously "safe math" code.

@j4james commented on GitHub (Apr 7, 2020): FYI, I've just tested with the first open source release (commit d4d59fa3395012ca37ba12665da4ec11c7dcf9cb), and the bug was already present there. However, the legacy console doesn't have this issue. In some ways this is could be considered a part of issue #4153, but I thought it worth raising separately because of the crash, and the fact that it's not obviously "safe math" code.
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 7, 2020):

Regressed between RS5 (17763) and 19H1 (18362). Thanks!

@DHowett-MSFT commented on GitHub (Apr 7, 2020): Regressed between RS5 (17763) and 19H1 (18362). Thanks!
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 8, 2020):

Off triage, P2, /cc @miniksa for a conhost regression from the scrolling change in 19H1

@DHowett-MSFT commented on GitHub (Apr 8, 2020): Off triage, P2, /cc @miniksa for a conhost regression from the scrolling change in 19H1
Author
Owner

@ghost commented on GitHub (Mar 25, 2022):

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

Handy links:

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

@ghost commented on GitHub (Mar 25, 2022):

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

Handy links:

@ghost commented on GitHub (Mar 25, 2022): :tada:This issue was addressed in #12669, which has now been successfully released as `Windows Terminal Preview v1.13.1073`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.13.1073) * [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#7324