[PR #4202] Guard the substring calls in StateMachine parser to avoid bounds issues #25696

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

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

State: closed
Merged: Yes


Summary of the Pull Request

Perform checking on std::basic_string_view<T>.substr() calls to
prevent running out of bounds and sporadic Privileged Instruction throws
during x86 tests.

PR Checklist

  • Closes the x86 tests failing all over the place since #4125 for no
    apparent reason
  • I work here
  • Tests pass

Detailed Description of the Pull Request / Additional comments

It appears that not all std::basic_string_view<T>.substr() calls are
created equally. I rooted around for other versions of the code in our
source tree and found several versions that were less careful about
checking the start position and the size than the one that appears when
building locally on dev machines.

My theory is that one of these older versions is deployed somewhere in
the CI. Instead of clamping down the size parameter appropriately or
throwing correctly when the position is out of bounds, I believe that
it's just creating a substring with a bad range over an
invalid/uninitialized memory region. Then when the test operates on
that, sometimes it turns out to trigger the privileged instruction
NTSTATUS error we are seeing in CI.

Test Procedure

  1. Fixed the thing
  2. Ran the CI and it worked
  3. Reverted everything and turned off all of the CI build except just
    the parser tests (and supporting libraries)
  4. Ran CI and it failed
  5. Put the fix back on top (cherry-pick)
  6. It worked.
  7. Ran it again.
  8. It worked.
  9. Turn all the rest of the CI build back on
**Original Pull Request:** https://github.com/microsoft/terminal/pull/4202 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request Perform checking on `std::basic_string_view<T>.substr()` calls to prevent running out of bounds and sporadic Privileged Instruction throws during x86 tests. ## PR Checklist * [x] Closes the x86 tests failing all over the place since #4125 for no apparent reason * [x] I work here * [x] Tests pass ## Detailed Description of the Pull Request / Additional comments It appears that not all `std::basic_string_view<T>.substr()` calls are created equally. I rooted around for other versions of the code in our source tree and found several versions that were less careful about checking the start position and the size than the one that appears when building locally on dev machines. My theory is that one of these older versions is deployed somewhere in the CI. Instead of clamping down the size parameter appropriately or throwing correctly when the position is out of bounds, I believe that it's just creating a substring with a bad range over an invalid/uninitialized memory region. Then when the test operates on that, sometimes it turns out to trigger the privileged instruction NTSTATUS error we are seeing in CI. ## Test Procedure 1. Fixed the thing 2. Ran the CI and it worked 3. Reverted everything and turned off all of the CI build except just the parser tests (and supporting libraries) 4. Ran CI and it failed 5. Put the fix back on top (cherry-pick) 6. It worked. 7. Ran it again. 8. It worked. 9. Turn all the rest of the CI build back on
claunia added the pull-request label 2026-01-31 09:11:10 +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#25696