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

Bug Report: if historySize >= 32728 a maximize doesn't redraw the terminal #2815

Closed
mcornella opened this issue Sep 19, 2019 · 5 comments · Fixed by #4964
Closed

Bug Report: if historySize >= 32728 a maximize doesn't redraw the terminal #2815

mcornella opened this issue Sep 19, 2019 · 5 comments · Fixed by #4964
Assignees
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@mcornella
Copy link

mcornella commented Sep 19, 2019

Environment

Windows build number: 10.0.18980.1
Windows Terminal version (if applicable): 0.4.2382.0

Any other software?

Steps to reproduce

  1. Set historySize of a profile to 32728 or bigger.
  2. Open a tab for that profile.
  3. Run commands so that there is a bunch of scroll space (running nano on Ubuntu is easier).
  4. Maximize the window.

Expected behavior

The terminal should redraw itself to occupy all the available space.

Actual behavior

The terminal keeps using the previously available space, not occupying the extra one. Some screenshots:

  1. After maximizing on Ubuntu:
    maximized on ubuntu

  2. After maximizing on cmd:
    maximized on cmd
    (Note the last dir output kept going but it was cut midway)

Other relevant information

A manual resize of the window does correctly trigger a redraw on Ubuntu. Not on cmd, which just keeps using the window space it had when the tab was opened.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 19, 2019
@DHowett-MSFT DHowett-MSFT added Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Sep 19, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Sep 19, 2019
@DHowett-MSFT DHowett-MSFT added this to the Terminal v1.0 milestone Sep 19, 2019
@DHowett-MSFT
Copy link
Contributor

Well, that's a thinker.

@j4james
Copy link
Collaborator

j4james commented Sep 20, 2019

Pretty much everything in the terminal implementation is a short, and while the initial history size is clamped, that's not enough to prevent an overflow when values are added. In this particular case, I believe the overflow is happening here:

const short newBufferHeight = viewportSize.Y + _scrollbackLines;

Clamping that result to SHORT_MAX seems to fix the issue, but I wouldn't want to bet on that being the only place that needs clamping. Conhost avoids the issue by limiting the scrollback to 9999, which seems like a safer approach.

@zadjii-msft
Copy link
Member

Welp, that's certainly my fault there. That's definitely wrong there, good find.

I think we should definitely make sure to use this issue as a chance to go through and audit some of our math in the Terminal code and make sure we're safemathing/clamping it. I clearly didn't do that originally, and we should be.

IIRC technically only the propsheet limits you to 9999 rows for conhost. I believe if you edit the registry directly, you can sidestep that to get to SHORT_MAX.

@j4james
Copy link
Collaborator

j4james commented Sep 25, 2019

IIRC technically only the propsheet limits you to 9999 rows for conhost. I believe if you edit the registry directly, you can sidestep that to get to SHORT_MAX.

Yeah, you're right. But that means conhost likely has many issues like this too, and I suspect it's going to be a nightmare to audit.

Just look at AdjustCursorPosition as one example. That looks like it has several potential overflows, but I'm guessing the end result is still OK because of the way two's complement works (although technically it may be undefined behaviour). If you started clamping all of those calculations, though, it would probably cause more problems than it solved.

Personally I'd just clamp the initial buffer size to something like 30000, if that meant we could avoid having to deal with all those edge cases.

@zadjii-msft zadjii-msft added the Priority-2 A description (P2) label Jan 22, 2020
@zadjii-msft zadjii-msft self-assigned this Mar 16, 2020
zadjii-msft added a commit that referenced this issue Mar 17, 2020
## Summary of the Pull Request

This is 100% on me. Even after mucking around in this function for the last 3
months, I missed that there was a single addition where we weren't doing a
clamped addition. This would lead to us creating a buffer with negative height,
and all sorts of badness.

Clamping this addition was enoguh to fix the bug.

## PR Checklist
* [x] Closes #2815
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* ran tests
* Created a profile with `"historySize" : 32728`, then filled the viewport with
  text, then maximized, and saw that the viewport indeed did resize to the new
  size of the window.
@ghost ghost added the In-PR This issue has a related PR label Mar 17, 2020
@ghost ghost closed this as completed in #4964 Mar 18, 2020
ghost pushed a commit that referenced this issue Mar 18, 2020
## Summary of the Pull Request

This is 100% on me. Even after mucking around in this function for the last 3
months, I missed that there was a single addition where we weren't doing a
clamped addition. This would lead to us creating a buffer with negative height,
and all sorts of badness.

Clamping this addition was enough to fix the bug.

## PR Checklist
* [x] Closes #2815
* [x] Closes #4972
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* ran tests
* Created a profile with `"historySize" : 32728`, then filled the viewport with
  text, then maximized, and saw that the viewport indeed did resize to the new
  size of the window.
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Mar 18, 2020
DHowett-MSFT pushed a commit that referenced this issue Mar 19, 2020
## Summary of the Pull Request

This is 100% on me. Even after mucking around in this function for the last 3
months, I missed that there was a single addition where we weren't doing a
clamped addition. This would lead to us creating a buffer with negative height,
and all sorts of badness.

Clamping this addition was enough to fix the bug.

## PR Checklist
* [x] Closes #2815
* [x] Closes #4972
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* ran tests
* Created a profile with `"historySize" : 32728`, then filled the viewport with
  text, then maximized, and saw that the viewport indeed did resize to the new
  size of the window.

(cherry picked from commit f221cd2)
@ghost
Copy link

ghost commented Mar 20, 2020

🎉This issue was addressed in #4964, which has now been successfully released as Windows Terminal Preview v0.10.781.0.:tada:

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants