-
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
Fix SetConsoleWindowInfo being able to crash ConPTY #13212
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2268,30 +2268,19 @@ void SCREEN_INFORMATION::SetViewport(const Viewport& newViewport, | |
} | ||
|
||
// do adjustments on a copy that's easily manipulated. | ||
auto srCorrected = newViewport.ToExclusive(); | ||
const til::rect viewportRect{ newViewport.ToInclusive() }; | ||
const til::size coordScreenBufferSize{ GetBufferSize().Dimensions() }; | ||
|
||
if (srCorrected.Left < 0) | ||
{ | ||
srCorrected.Right -= srCorrected.Left; | ||
srCorrected.Left = 0; | ||
} | ||
if (srCorrected.Top < 0) | ||
{ | ||
srCorrected.Bottom -= srCorrected.Top; | ||
srCorrected.Top = 0; | ||
} | ||
// MSFT-33471786, GH#13193: | ||
// newViewport may reside anywhere outside of the valid coordScreenBufferSize. | ||
// For instance it might be scrolled down more than our text buffer allows to be scrolled. | ||
const auto cx = gsl::narrow_cast<SHORT>(std::clamp(viewportRect.width(), 1, coordScreenBufferSize.width)); | ||
const auto cy = gsl::narrow_cast<SHORT>(std::clamp(viewportRect.height(), 1, coordScreenBufferSize.height)); | ||
const auto x = gsl::narrow_cast<SHORT>(std::clamp(viewportRect.left, 0, coordScreenBufferSize.width - cx)); | ||
const auto y = gsl::narrow_cast<SHORT>(std::clamp(viewportRect.top, 0, coordScreenBufferSize.height - cy)); | ||
Comment on lines
+2277
to
+2280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function needs to correct the I feel like this change increases the robustness of the code by splitting the viewport into its size (cx/cy) and origin (x/y). That way we can first ensure that the size doesn't exceed our limits (just like the old code seemingly intended) and then adjust the origin to be within the smaller rectangle of valid coordinates. The |
||
|
||
const auto coordScreenBufferSize = GetBufferSize().Dimensions(); | ||
if (srCorrected.Right > coordScreenBufferSize.X) | ||
{ | ||
srCorrected.Right = coordScreenBufferSize.X; | ||
} | ||
if (srCorrected.Bottom > coordScreenBufferSize.Y) | ||
{ | ||
srCorrected.Bottom = coordScreenBufferSize.Y; | ||
} | ||
_viewport = Viewport::FromExclusive({ x, y, x + cx, y + cy }); | ||
|
||
_viewport = Viewport::FromExclusive(srCorrected); | ||
if (updateBottom) | ||
{ | ||
UpdateBottom(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious, why not allow a width/height of 0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimum size the
TextBuffer
allows is(1,1)
, so I thought it'd be reasonable if we did the same here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A text buffer with a zero dimension would not be a particularly useful text buffer :)