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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/renderer/base/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

{
continue;
}
Expand Down
14 changes: 12 additions & 2 deletions src/types/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ Viewport Viewport::FromDimensions(const COORD origin,
const short width,
const short height) noexcept
{
return Viewport::FromExclusive({ origin.X, origin.Y, origin.X + width, origin.Y + height });
return Viewport::FromInclusive({
origin.X,
origin.Y,
base::saturated_cast<short>(origin.X + width - 1),
base::saturated_cast<short>(origin.Y + height - 1),
});
}

// Function Description:
Expand All @@ -60,7 +65,12 @@ Viewport Viewport::FromDimensions(const COORD origin,
Viewport Viewport::FromDimensions(const COORD origin,
const COORD dimensions) noexcept
{
return Viewport::FromExclusive({ origin.X, origin.Y, origin.X + dimensions.X, origin.Y + dimensions.Y });
return Viewport::FromInclusive({
origin.X,
origin.Y,
base::saturated_cast<short>(origin.X + dimensions.X - 1),
base::saturated_cast<short>(origin.Y + dimensions.Y - 1),
});
}

// Function Description:
Expand Down