"invalid bounds arguments passed to std::clamp" when resizing window to zero height #17257

Open
opened 2026-01-31 05:36:57 +00:00 by claunia · 0 comments
Owner

Originally created by @Predelnik on GitHub (Apr 16, 2022).

Windows Terminal version

1.12.10733.0

Windows build number

10.0.22000

Other Software

No response

Steps to reproduce

Launch OpenConsole.exe compiled in debug mode, drag bottom of the window to the very top.

Expected Behavior

No assertion

Actual Behavior

Assertion from from STL "invalid bounds arguments passed to std::clamp" on the line

clampMe.Top = std::clamp(clampMe.Top, Top(), BottomInclusive());

in Viewport Viewport::Clamp

Call stack
 	ucrtbased.dll!00007ff9248a7fbc()	Unknown
 	ucrtbased.dll!00007ff9248a7ef4()	Unknown
 	ucrtbased.dll!00007ff9248a7d90()	Unknown
>	OpenConsole.exe!std::clamp>(const short & _Val, const short & _Min_val, const short & _Max_val, std::less _Pred) Line 10188	C++
 	OpenConsole.exe!std::clamp(const short & _Val, const short & _Min_val, const short & _Max_val) Line 10208	C++
 	OpenConsole.exe!Microsoft::Console::Types::Viewport::Clamp(const Microsoft::Console::Types::Viewport & other) Line 245	C++
 	OpenConsole.exe!Microsoft::Console::Render::Renderer::TriggerRedrawCursor(const _COORD * const pcoord) Line 284	C++
 	OpenConsole.exe!TextBuffer::TriggerRedrawCursor(const _COORD position) Line 992	C++
 	OpenConsole.exe!Cursor::_RedrawCursorAlways() Line 190	C++
 	OpenConsole.exe!Cursor::SetIsOn(const bool fIsOn) Line 103	C++
 	OpenConsole.exe!Microsoft::Console::CursorBlinker::TimerRoutine(SCREEN_INFORMATION & ScreenInfo) Line 153	C++
 	OpenConsole.exe!CursorTimerRoutineWrapper(_TP_CALLBACK_INSTANCE * __formal, void * __formal, _TP_TIMER * __formal) Line 24	C++
 	ntdll.dll!TppTimerpExecuteCallback()	Unknown
 	ntdll.dll!TppWorkerThread()	Unknown
 	kernel32.dll!00007ff9feee54e0()	Unknown
 	ntdll.dll!RtlUserThreadStart()	Unknown

Looks like it happens because SCREEN_INFORMATION::_InternalSetViewportSize increases viewport's Top in srNewViewport.Top -= DeltaY; (DeltaY is negative) line without any check to prevent Top becoming more than Bottom which sadly can happen. Clamp cannot work when Top is more than Bottom

Originally created by @Predelnik on GitHub (Apr 16, 2022). ### Windows Terminal version 1.12.10733.0 ### Windows build number 10.0.22000 ### Other Software _No response_ ### Steps to reproduce Launch OpenConsole.exe compiled in debug mode, drag bottom of the window to the very top. ### Expected Behavior No assertion ### Actual Behavior Assertion from from STL `"invalid bounds arguments passed to std::clamp"` on the line ```cpp clampMe.Top = std::clamp(clampMe.Top, Top(), BottomInclusive()); ``` in `Viewport Viewport::Clamp` <details> <summary>Call stack</summary> <pre> ucrtbased.dll!00007ff9248a7fbc() Unknown ucrtbased.dll!00007ff9248a7ef4() Unknown ucrtbased.dll!00007ff9248a7d90() Unknown > OpenConsole.exe!std::clamp<short,std::less<void>>(const short & _Val, const short & _Min_val, const short & _Max_val, std::less<void> _Pred) Line 10188 C++ OpenConsole.exe!std::clamp<short>(const short & _Val, const short & _Min_val, const short & _Max_val) Line 10208 C++ OpenConsole.exe!Microsoft::Console::Types::Viewport::Clamp(const Microsoft::Console::Types::Viewport & other) Line 245 C++ OpenConsole.exe!Microsoft::Console::Render::Renderer::TriggerRedrawCursor(const _COORD * const pcoord) Line 284 C++ OpenConsole.exe!TextBuffer::TriggerRedrawCursor(const _COORD position) Line 992 C++ OpenConsole.exe!Cursor::_RedrawCursorAlways() Line 190 C++ OpenConsole.exe!Cursor::SetIsOn(const bool fIsOn) Line 103 C++ OpenConsole.exe!Microsoft::Console::CursorBlinker::TimerRoutine(SCREEN_INFORMATION & ScreenInfo) Line 153 C++ OpenConsole.exe!CursorTimerRoutineWrapper(_TP_CALLBACK_INSTANCE * __formal, void * __formal, _TP_TIMER * __formal) Line 24 C++ ntdll.dll!TppTimerpExecuteCallback() Unknown ntdll.dll!TppWorkerThread() Unknown kernel32.dll!00007ff9feee54e0() Unknown ntdll.dll!RtlUserThreadStart() Unknown </pre> </details> Looks like it happens because `SCREEN_INFORMATION::_InternalSetViewportSize` increases viewport's `Top` in `srNewViewport.Top -= DeltaY;` (`DeltaY` is negative) line without any check to prevent `Top` becoming more than `Bottom` which sadly can happen. Clamp cannot work when `Top` is more than `Bottom`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17257