[PR #1254] Bugfix: crash on copying resized selection #24542

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

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

State: closed
Merged: Yes


Summary of the Pull Request

The selection anchors would become outside of the new size. They didn't matter for rendering the selection, but they would crash on the copy because we would actually try to read the buffer in a non-existent space.

Solution: clamp the anchors at RENDER TIME
That way, if we have the window resize again AND the anchors are valid, draw them appropriately.
I think this is better than just clearing a selection after a resize event, BUT if you disagree, I guess we can add that in pretty easily.

References

#1165 specifically mentions resizing so I'll close that one. Just be aware that there is a chance #1246 could be what's happening too.

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • clamp when you're extracting data from buffer
  • also moved the _buffer->GetSize().RightInclusive() out of the for loop so I guess it's more performant?

Validation Steps Performed

  1. Maximize window
  2. Create a scroll region (just do "dir" or "ls" a bunch)
  3. Scroll to somewhere in the middle
  4. Select top-left corner, then right-most side 3 lines down (so select 3 full lines)
  5. Unmaximize window
  6. Right-click to copy

Used to crash, now you should get all three lines in your clipboard.

NOTE: if you copy the same selection in a maximized state vs unmaximized state, it will be slightly different BECAUSE the right side of the buffer is now cropped.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/1254 **State:** closed **Merged:** Yes --- <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request The selection anchors would become outside of the new size. They didn't matter for rendering the selection, but they would crash on the copy because we would actually try to read the buffer in a non-existent space. Solution: clamp the anchors at RENDER TIME That way, if we have the window resize again AND the anchors are valid, draw them appropriately. I think this is better than just clearing a selection after a resize event, BUT if you disagree, I guess we can add that in pretty easily. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References #1165 specifically mentions resizing so I'll close that one. Just be aware that there is a chance #1246 could be what's happening too. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #1165 * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [x] Requires documentation to be updated * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments - clamp when you're extracting data from buffer - also moved the `_buffer->GetSize().RightInclusive()` out of the for loop so I guess it's more performant? <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed 1. Maximize window 2. Create a scroll region (just do "dir" or "ls" a bunch) 3. Scroll to somewhere in the middle 4. Select top-left corner, then right-most side 3 lines down (so select 3 full lines) 5. Unmaximize window 6. Right-click to copy Used to crash, now you should get all three lines in your clipboard. NOTE: if you copy the same selection in a maximized state vs unmaximized state, it will be slightly different BECAUSE the right side of the buffer is now cropped.
claunia added the pull-request label 2026-01-31 09:03:54 +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#24542