Crash in ScrollConsoleScreenBuffer when destination coordinates overflow #7322

Open
opened 2026-01-31 01:01:01 +00:00 by claunia · 0 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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7322