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

AtlasEngine: Fix a heap overflow bug #14275

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Oct 21, 2022

TextBuffer is buggy and allows a Trailing DbcsAttribute to be written
into the first column. Since other code then blindly assumes that there's a
preceding Leading character, we'll get called with a X coordinate of -1.
This issue will be fixed by #13626 and this commit fixes it in the meantime.

Additionally fixes an unimportant crash when the window height is 0px,
because it was annoying during testing and doesn't hurt to be fixed.

Validation Steps Performed

  • Run a stress test that prints random Unicode at random positions
  • Resize the window furiously at the same time
  • Doesn't crash / fail-fast ✅

@lhecker lhecker added Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Area-AtlasEngine labels Oct 21, 2022
@lhecker lhecker added this to the Terminal v1.17 milestone Oct 21, 2022
{
_api.invalidatedRows.x = 0;
_api.invalidatedRows.y = gsl::narrow_cast<u16>(clamp<int>(_api.invalidatedRows.y + delta, u16min, u16max));
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is way less egregious if you suppress whitespace changes.

This block of changes is unrelated to this PR but represent an earlier attempt at fixing it. I left it in because it'll help with implementing horizontal scrolling in the future.

gsl::narrow_cast<u16>(srNewViewport.Right - srNewViewport.Left + 1),
gsl::narrow_cast<u16>(srNewViewport.Bottom - srNewViewport.Top + 1),
gsl::narrow_cast<u16>(std::max(1, srNewViewport.Right - srNewViewport.Left + 1)),
gsl::narrow_cast<u16>(std::max(1, srNewViewport.Bottom - srNewViewport.Top + 1)),
Copy link
Member Author

Choose a reason for hiding this comment

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

Prevents an orderly/expected crash when you resize the conhost window down to 0px height.

std::fill_n(_api.bufferLineMetadata.data() + x, column - x, metadata);
}

_api.lastPaintBufferLineCoord = { x, y };
_api.bufferLineWasHyperlinked = false;
Copy link
Member Author

Choose a reason for hiding this comment

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

This block moved down since I'm computing x late now.

}

auto column = x;
clusters = clusters.subspan(offset);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The fix.

// into the first column. Since other code then blindly assumes that there's a
// preceding `Leading` character, we'll get called with a X coordinate of -1.
//
// This block can be removed after GH#13626 is merged.
Copy link
Member

Choose a reason for hiding this comment

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

we will never remember this

Copy link
Member Author

Choose a reason for hiding this comment

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

Eh, we don't really have to. This is a small, self-contained snippet and so I feel like it can be removed whenever. But I'll add a note to make this change in my ROW PR.

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Oct 31, 2022
@lhecker lhecker merged commit bb4711d into main Nov 2, 2022
@lhecker lhecker deleted the dev/lhecker/atlas-engine-heap-overflow branch November 2, 2022 02:12
DHowett pushed a commit that referenced this pull request Dec 1, 2022
`TextBuffer` is buggy and allows a `Trailing` `DbcsAttribute` to be written
into the first column. Since other code then blindly assumes that there's a
preceding `Leading` character, we'll get called with a X coordinate of -1.
This issue will be fixed by #13626 and this commit fixes it in the meantime.

Additionally fixes an unimportant crash when the window height is 0px,
because it was annoying during testing and doesn't hurt to be fixed.

## Validation Steps Performed
* Run a stress test that prints random Unicode at random positions
* Resize the window furiously at the same time
* Doesn't crash / fail-fast ✅

(cherry picked from commit bb4711d)
Service-Card-Id: 86353783
Service-Version: 1.16
@ghost
Copy link

ghost commented Dec 14, 2022

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

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AtlasEngine AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants