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 DBCS attribute corruption during reflow #12853

Merged
3 commits merged into from Apr 8, 2022
Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Apr 7, 2022

855e136 contains a regression which breaks buffer reflow if wide surrogate
characters are present. This happens because we made use of the
TextBufferCellIterator whose increment operator skips 2 cells for wide
characters. This created a "misalignment" in the reflow logic which was written
for cell-wise iteration. This commit fixes the issue, by reverting back to the
previous algorithm without iterators.

Closes #12837
Closes MSFT-38904421

Validation Steps Performed

  • Run pwsh -noprofile -command echo "`u{D83D}`u{DE43}"
  • Resizing conhost preserves all contents ✅
  • Resizing Windows Terminal doesn't crash it ✅
  • Added a test covering this issue ✅

@lhecker lhecker requested a review from zadjii-msft April 7, 2022 17:47
@ghost ghost added Area-Accessibility Issues related to accessibility Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. Severity-Crash Crashes are real bad news. labels Apr 7, 2022
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

The newAttrColumn thing seems like it would regress the original bug we fixed.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Apr 7, 2022
@DHowett
Copy link
Member

DHowett commented Apr 7, 2022

We will not erroneously copy a DBCS Trailing Attribute to the edge of the screen, right? Or a leading one?

@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Apr 7, 2022
@lhecker
Copy link
Member Author

lhecker commented Apr 7, 2022

We will not erroneously copy a DBCS Trailing Attribute to the edge of the screen, right? Or a leading one?

I'll have to check! This PR could've been a draft tbh. 😅
I'll need a bit to write a unit test and test this more thoroughly.

{
try
{
// TODO: MSFT: 19446208 - this should just use an iterator and the inserter...
const auto textAttr = *attrs;
const auto textAttr = row.GetAttrRow().GetAttrByColumn(copyAttrCol);
Copy link
Member

Choose a reason for hiding this comment

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

sad that this beautiful optimization had to die

const auto dbcsAttr = chars->DbcsAttr();
const auto textAttr = *attrs;
const auto glyph = row.GetCharRow().GlyphAt(iOldCol);
const auto dbcsAttr = row.GetCharRow().DbcsAttrAt(iOldCol);
Copy link
Member

Choose a reason for hiding this comment

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

ah cause chars++ might skip two columns for something like an emoji, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think so.

@DHowett
Copy link
Member

DHowett commented Apr 7, 2022

So, here is my hope.

WinDev is in "ask" mode locally, so I'm just gonna take this fix up during Ask for both Terminal and Console.
We need this to be rock solid. I need tests for resizing single- and double- width surrogate pairs, at the edge of the buffer, wider and narrower.
I need to understand the impact on Terminal, and I think we should wrap UpdatePatternLocationsUnderLock in a try/catch just to be safe so that any future regressions here only break URL updating and don't cause a crash.
We're in a tight corner here. :)

@lhecker lhecker added this to To Cherry Pick in 1.12 Servicing Pipeline via automation Apr 7, 2022
@lhecker lhecker added this to To Cherry Pick in Inbox Servicing Pipeline via automation Apr 7, 2022
@lhecker lhecker added this to To Cherry Pick in 1.13 Servicing Pipeline via automation Apr 7, 2022
@lhecker lhecker requested a review from DHowett April 8, 2022 16:55
@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Apr 8, 2022
@ghost
Copy link

ghost commented Apr 8, 2022

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 10b9044 into main Apr 8, 2022
@ghost ghost deleted the dev/lhecker/12837-reflow-fix branch April 8, 2022 17:26
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in Inbox Servicing Pipeline Apr 8, 2022
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.12 Servicing Pipeline Apr 8, 2022
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.13 Servicing Pipeline Apr 8, 2022
DHowett pushed a commit that referenced this pull request Apr 8, 2022
855e136 contains a regression which breaks buffer reflow if wide surrogate
characters are present. This happens because we made use of the
`TextBufferCellIterator` whose increment operator skips 2 cells for wide
characters. This created a "misalignment" in the reflow logic which was written
for cell-wise iteration. This commit fixes the issue, by reverting back to the
previous algorithm without iterators.

Closes #12837
Closes MSFT-38904421

## Validation Steps Performed
* Run ``pwsh -noprofile -command echo "`u{D83D}`u{DE43}"``
* Resizing conhost preserves all contents ✅
* Resizing Windows Terminal doesn't crash it ✅
* Added a test covering this issue ✅

(cherry picked from commit 10b9044)
Service-Card-Id: 80340089
Service-Version: 1.12
DHowett pushed a commit that referenced this pull request Apr 8, 2022
855e136 contains a regression which breaks buffer reflow if wide surrogate
characters are present. This happens because we made use of the
`TextBufferCellIterator` whose increment operator skips 2 cells for wide
characters. This created a "misalignment" in the reflow logic which was written
for cell-wise iteration. This commit fixes the issue, by reverting back to the
previous algorithm without iterators.

Closes #12837
Closes MSFT-38904421

## Validation Steps Performed
* Run ``pwsh -noprofile -command echo "`u{D83D}`u{DE43}"``
* Resizing conhost preserves all contents ✅
* Resizing Windows Terminal doesn't crash it ✅
* Added a test covering this issue ✅

(cherry picked from commit 10b9044)
Service-Card-Id: 80340090
Service-Version: 1.13
@ghost
Copy link

ghost commented Apr 19, 2022

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

Handy links:

@ghost
Copy link

ghost commented Apr 19, 2022

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

Handy links:

@DHowett DHowett moved this from Cherry Picked to Validated in 1.13 Servicing Pipeline May 10, 2022
@DHowett DHowett moved this from Validated to Shipped in 1.13 Servicing Pipeline May 10, 2022
@DHowett DHowett moved this from Cherry Picked to Shipped in Inbox Servicing Pipeline Jun 7, 2022
DHowett pushed a commit that referenced this pull request Jun 24, 2022
855e136 contains a regression which breaks buffer reflow if wide surrogate
characters are present. This happens because we made use of the
`TextBufferCellIterator` whose increment operator skips 2 cells for wide
characters. This created a "misalignment" in the reflow logic which was written
for cell-wise iteration. This commit fixes the issue, by reverting back to the
previous algorithm without iterators.

Closes #12837
Closes MSFT-38904421

## Validation Steps Performed
* Run ``pwsh -noprofile -command echo "`u{D83D}`u{DE43}"``
* Resizing conhost preserves all contents ✅
* Resizing Windows Terminal doesn't crash it ✅
* Added a test covering this issue ✅

(cherry picked from commit 10b9044)
Service-Card-Id: 80340091
Service-Version: Inbox
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-Accessibility Issues related to accessibility 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-0 Bugs that we consider release-blocking/recall-class (P0) Product-Terminal The new Windows Terminal. Severity-Blocking We won't ship a release like this! No-siree. Severity-Crash Crashes are real bad news.
Projects
4 participants