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

Open
opened 2026-01-31 09:36:47 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/13779
Author: @carlos-zamora
Created: 8/18/2022
Status: Merged
Merged: 8/25/2022
Merged by: @undefined

Base: mainHead: dev/cazamor/a11y/sure-why-not


📝 Commits (6)

  • 37232ed [UIA] Assume GetText(INT_MAX) just wants the whole text
  • b44869c early exit; more robust resize check
  • e61203f fix minor bug
  • fec9bc1 reserve and return early
  • d39a948 I <3 ClampedNumeric
  • 83e3c5d simplify

📊 Changes

1 file changed (+16 additions, -6 deletions)

View changed files

📝 src/types/UiaTextRangeBase.cpp (+16 -6)

📄 Description

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).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/13779 **Author:** [@carlos-zamora](https://github.com/carlos-zamora) **Created:** 8/18/2022 **Status:** ✅ Merged **Merged:** 8/25/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/cazamor/a11y/sure-why-not` --- ### 📝 Commits (6) - [`37232ed`](https://github.com/microsoft/terminal/commit/37232ed15fde5d0accb791e77c063c364e1fa824) [UIA] Assume GetText(INT_MAX) just wants the whole text - [`b44869c`](https://github.com/microsoft/terminal/commit/b44869cfba034fbb09eef0200feb8be3baedfcc0) early exit; more robust resize check - [`e61203f`](https://github.com/microsoft/terminal/commit/e61203f0202ec2025f827882eefa14c66ba3b8ea) fix minor bug - [`fec9bc1`](https://github.com/microsoft/terminal/commit/fec9bc178e4affaec365a56f0e2d486c7ea86794) reserve and return early - [`d39a948`](https://github.com/microsoft/terminal/commit/d39a94813dcfbd1a8bb26595046c081b62b68f99) I <3 ClampedNumeric - [`83e3c5d`](https://github.com/microsoft/terminal/commit/83e3c5dfdaeb9eb383b677e479ed9eca59f0b613) simplify ### 📊 Changes **1 file changed** (+16 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/types/UiaTextRangeBase.cpp` (+16 -6) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:36:47 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#29766