Skip to content
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 overflow in Viewport::FromDimensions #12669

Merged
1 commit merged into from
Mar 11, 2022
Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Mar 11, 2022

This removes one source of potential integer overflows from the Viewport class.
Other parts were left untouched, as this entire class of overflow issues gets
fixed all at once, as soon as we replace COORD with til::coord (etc.).

PR Checklist

Validation Steps Performed

  • Call ScrollConsoleScreenBufferW with out of bounds coordinates
  • Doesn't crash ✅

@ghost ghost added Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Impact-Correctness It be wrong. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conhost For issues in the Console codebase Severity-Crash Crashes are real bad news. labels Mar 11, 2022
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man this Viewport class needs to go, doesn't it?

@lhecker
Copy link
Member Author

lhecker commented Mar 11, 2022

Man this Viewport class needs to go, doesn't it?

This and SMALL_RECT. I hope we can get my til::coord/size/rect PR merged for the next WT version, even if it's a grand total of around 9000 LOC diff. It removes like 99% of the SMALL_RECT use and practically 100% of all int -> short narrowing bugs like this one.

@@ -677,8 +677,7 @@ void Renderer::_PaintBufferOutput(_In_ IRenderEngine* const pEngine)

for (const auto& dirtyRect : dirtyAreas)
{
// Shortcut: don't bother redrawing if the width is 0.
if (dirtyRect.left == dirtyRect.right)
if (!dirtyRect)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW This is a bug. Some engines return dirty rects where top == bottom, and I don't think any engine returns left == right actually. This causes an invalid Viewport to be created a few lines below. In either case though, this now checks both dimensions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wuh oh. good catch then.

@DHowett DHowett added the zInbox-Bug Ignore me! label Mar 11, 2022
@DHowett
Copy link
Member

DHowett commented Mar 11, 2022

@msftbot merge this in 1 minute

@ghost ghost added the AutoMerge Marked for automatic merge by the bot when requirements are met label Mar 11, 2022
@ghost
Copy link

ghost commented Mar 11, 2022

Hello @DHowett!

Because you've given me some instructions on how to help merge this pull request, I'll be modifying my merge approach. Here's how I understand your requirements for merging this pull request:

  • I won't merge this pull request until after the UTC date Fri, 11 Mar 2022 21:13:23 GMT, which is in 1 minute

If this doesn't seem right to you, you can tell me to cancel these instructions and use the auto-merge policy that has been configured for this repository. Try telling me "forget everything I just told you".

@ghost ghost merged commit a4a6dfc into main Mar 11, 2022
@ghost ghost deleted the dev/lhecker/5271-viewport-overflow branch March 11, 2022 21:14
DHowett pushed a commit that referenced this pull request Mar 11, 2022
This removes one source of potential integer overflows from the Viewport class.
Other parts were left untouched, as this entire class of overflow issues gets
 fixed all at once, as soon as we replace COORD with til::coord (etc.).

* [x] Closes #5271
* [x] I work here
* [x] Tests added/passed

* Call `ScrollConsoleScreenBufferW` with out of bounds coordinates
* Doesn't crash ✅

(cherry picked from commit a4a6dfc)
DHowett pushed a commit that referenced this pull request Mar 11, 2022
This removes one source of potential integer overflows from the Viewport class.
Other parts were left untouched, as this entire class of overflow issues gets
 fixed all at once, as soon as we replace COORD with til::coord (etc.).

## PR Checklist
* [x] Closes #5271
* [x] I work here
* [x] Tests added/passed

## Validation Steps Performed
* Call `ScrollConsoleScreenBufferW` with out of bounds coordinates
* Doesn't crash ✅

(cherry picked from commit a4a6dfc)
Signed-off-by: Dustin Howett <duhowett@microsoft.com>
DHowett pushed a commit that referenced this pull request Mar 24, 2022
This removes one source of potential integer overflows from the Viewport class.
Other parts were left untouched, as this entire class of overflow issues gets
 fixed all at once, as soon as we replace COORD with til::coord (etc.).

## PR Checklist
* [x] Closes #5271
* [x] I work here
* [x] Tests added/passed

## Validation Steps Performed
* Call `ScrollConsoleScreenBufferW` with out of bounds coordinates
* Doesn't crash ✅

(cherry picked from commit a4a6dfc)
@ghost
Copy link

ghost commented Mar 25, 2022

🎉Windows Terminal v1.12.1073 has been released which incorporates this pull request.:tada:

Handy links:

@ghost
Copy link

ghost commented Mar 25, 2022

🎉Windows Terminal Preview v1.13.1073 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. AutoMerge Marked for automatic merge by the bot when requirements are met Impact-Correctness It be wrong. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conhost For issues in the Console codebase Severity-Crash Crashes are real bad news. zInbox-Bug Ignore me!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash in ScrollConsoleScreenBuffer when destination coordinates overflow
3 participants