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

[UIA] Prevent erroneous L'\0' padding in GetText(INT_MAX) #13779

Merged
6 commits merged into from
Aug 25, 2022

Conversation

carlos-zamora
Copy link
Member

@carlos-zamora carlos-zamora commented Aug 18, 2022

Apparently, calling GetText(INT_MAX) causes a HUGE memory spike for a few seconds each time this is called. The UIA docs say to put -1 if no limit is required, but I assume a few people have been hit by this before.

This addresses this issue (and similar ones) in two ways:

  1. as we iterate over the lines of text, if we're already past the max length, just break out of the loop
  2. only resize if the max length is actually less than the current length. This prevents us padding the string with L'\0' erroneously (which is probably what causes the memory spike).

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

cause of course

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.

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 18, 2022
@lhecker lhecker added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-Accessibility Issues related to accessibility Product-Terminal The new Windows Terminal. Priority-2 A description (P2) labels Aug 18, 2022
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 19, 2022
@carlos-zamora carlos-zamora changed the title [UIA] Assume GetText(INT_MAX) just wants the whole text [UIA] Prevent erroneous L'\0' padding in GetText(INT_MAX) Aug 19, 2022
lhecker
lhecker previously approved these changes Aug 19, 2022
@lhecker lhecker dismissed their stale review August 19, 2022 00:48

There's a small bug remaining

src/types/UiaTextRangeBase.cpp Outdated Show resolved Hide resolved
src/types/UiaTextRangeBase.cpp Outdated Show resolved Hide resolved
@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 19, 2022
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Aug 19, 2022
@carlos-zamora

This comment was marked as resolved.

@carlos-zamora
Copy link
Member Author

Decided to keep the narrow_cast<size_t>(-1) because it really simplifies things. I can directly store that value and reuse it (especially in the loop). The alternative would be to have each if-statement check (1) maxLength == -1 and (2) textData.size() > narrow_cast<size_t>(maxLength). Which is just annoying to deal with imo.

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

ghost commented Aug 25, 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 b4ada09 into main Aug 25, 2022
@ghost ghost deleted the dev/cazamor/a11y/sure-why-not branch August 25, 2022 17:04
DHowett pushed a commit that referenced this pull request Sep 6, 2022
Apparently, calling `GetText(INT_MAX)` causes a HUGE memory spike for a few seconds each time this is called. The [UIA docs](https://docs.microsoft.com/en-us/windows/win32/api/uiautomationcore/nf-uiautomationcore-itextrangeprovider-gettext#parameters) say to put `-1` if no limit is required, but I assume a few people have been hit by this before.

This addresses this issue (and similar ones) in two ways:
1. as we iterate over the lines of text, if we're already past the max length, just break out of the loop
2. _only_ resize if the max length is actually less than the current length. This prevents us padding the string with `L'\0'` erroneously (which is probably what causes the memory spike).

(cherry picked from commit b4ada09)
Service-Card-Id: 85252534
Service-Version: 1.15
@ghost
Copy link

ghost commented Sep 13, 2022

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

Handy links:

@ghost
Copy link

ghost commented Sep 13, 2022

🎉Windows Terminal Preview v1.16.252 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-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-2 A description (P2) Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants