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

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

Original Pull Request: https://github.com/microsoft/terminal/pull/13779

State: closed
Merged: Yes


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).
**Original Pull Request:** https://github.com/microsoft/terminal/pull/13779 **State:** closed **Merged:** Yes --- 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).
claunia added the pull-request label 2026-01-31 09:36:48 +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#29771