[PR #17567] Fix various Read/WriteConsoleOutput bugs #31269

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

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

State: closed
Merged: Yes


Split off from #17510:

  • Viewport::Clamp used std::clamp to calculate the intersection
    between two rectangles. That works for exclusive rectangles,
    because .left == .right indicates an empty rectangle.
    But Viewport is an inclusive one, and so .left == .right is
    non-empty. For instance, if the to-be-clamped rect is fully
    outside the bounding rect, the result is a 1x1 viewport.
    In effect this meant that Viewport::Clamp never clamped so far.
  • The targetArea < targetBuffer.size() check is the wrong way around.
    It should be targetArea > targetBuffer.size().
  • The sourceSize and targetSize checks are incorrect, because the
    rectangles may be non-empty but outside the valid bounding rect.
  • If these sizes were empty, we'd return the requested rectangle which
    is a regression since conhost v1 and violates the API contract.
  • The sourceRect emptiness check is incorrect, because the clamping
    logic before it doesn't actually clamp to the bounding rect.
  • The entire clamping and iteration logic is just overall too complex.
**Original Pull Request:** https://github.com/microsoft/terminal/pull/17567 **State:** closed **Merged:** Yes --- Split off from #17510: * `Viewport::Clamp` used `std::clamp` to calculate the intersection between two rectangles. That works for exclusive rectangles, because `.left == .right` indicates an empty rectangle. But `Viewport` is an inclusive one, and so `.left == .right` is non-empty. For instance, if the to-be-clamped rect is fully outside the bounding rect, the result is a 1x1 viewport. In effect this meant that `Viewport::Clamp` never clamped so far. * The `targetArea < targetBuffer.size()` check is the wrong way around. It should be `targetArea > targetBuffer.size()`. * The `sourceSize` and `targetSize` checks are incorrect, because the rectangles may be non-empty but outside the valid bounding rect. * If these sizes were empty, we'd return the requested rectangle which is a regression since conhost v1 and violates the API contract. * The `sourceRect` emptiness check is incorrect, because the clamping logic before it doesn't actually clamp to the bounding rect. * The entire clamping and iteration logic is just overall too complex.
claunia added the pull-request label 2026-01-31 09:46:11 +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#31269