Incorrect interpretation of DECSTBM parameters #2601

Open
opened 2026-01-30 22:59:25 +00:00 by claunia · 0 comments
Owner

Originally created by @j4james on GitHub (Jul 6, 2019).

Originally assigned to: @j4james on GitHub.

Environment

Windows build number: Version 10.0.18362.145

Steps to reproduce

While testing the DECSTBM escape sequence for setting the scroll margins, I noticed a couple of edge cases where the margin parameters are interpreted incorrectly.

  1. If the top margin is equal to the bottom margin, the command should be ignored, but the current interpretation sets the margins to full screen.

  2. If the bottom margin is greater than the screen height, the command should be ignored, but the current implementation allows it to extend beyond the bottom of the screen.

You can reproduce these issues with a couple of printf commands in a bash shell.

  1. printf "\ec\e[5;20r\e[5;5r\e[10H\e[999Atop\r\e[999Bbottom\e[r\n"

  2. printf "\ec\e[5;20r\e[10;200r\e[15H\e[999Atop\r\e[999Bbottom\e[r\n"

Expected behavior

In both of the above test cases, I'd expect the top to be written on line 5, and the bottom to be written on line 20 (i.e. the initial 5;20 margin range, before the attempt to set an invalid margin).

This behaviour is explicitly stated in the DEC STD 070 Video Systems Reference Manual (see notes 2 and 3):

image

Actual behavior

  1. For the first case, the Windows terminal sets the margins to full screen, so the top is output on the first line, and the bottom is on the last line.

  2. For the second case, the Windows terminal sets the out-of-range margin exactly as requested, although the bottom margin gives the appearance of being clamped to the screen height. This results in the top being output on line 10 and the bottom output on the last line.

There are actually a couple of variations to these bugs, but I think they're all symptoms of the same main issues.

Originally created by @j4james on GitHub (Jul 6, 2019). Originally assigned to: @j4james on GitHub. # Environment ```none Windows build number: Version 10.0.18362.145 ``` # Steps to reproduce While testing the DECSTBM escape sequence for setting the scroll margins, I noticed a couple of edge cases where the margin parameters are interpreted incorrectly. 1. If the top margin is equal to the bottom margin, the command should be ignored, but the current interpretation sets the margins to full screen. 2. If the bottom margin is greater than the screen height, the command should be ignored, but the current implementation allows it to extend beyond the bottom of the screen. You can reproduce these issues with a couple of `printf` commands in a bash shell. 1. ```printf "\ec\e[5;20r\e[5;5r\e[10H\e[999Atop\r\e[999Bbottom\e[r\n"``` 2. ```printf "\ec\e[5;20r\e[10;200r\e[15H\e[999Atop\r\e[999Bbottom\e[r\n"``` # Expected behavior In both of the above test cases, I'd expect the `top` to be written on line 5, and the `bottom` to be written on line 20 (i.e. the initial 5;20 margin range, before the attempt to set an invalid margin). This behaviour is explicitly stated in the DEC STD 070 Video Systems Reference Manual (see notes 2 and 3): ![image](https://user-images.githubusercontent.com/4181424/60749357-b7d7f000-9f90-11e9-8e8f-7ddc816f9847.png) # Actual behavior 1. For the first case, the Windows terminal sets the margins to full screen, so the `top` is output on the first line, and the `bottom` is on the last line. 2. For the second case, the Windows terminal sets the out-of-range margin exactly as requested, although the bottom margin gives the appearance of being clamped to the screen height. This results in the `top` being output on line 10 and the `bottom` output on the last line. There are actually a couple of variations to these bugs, but I think they're all symptoms of the same main issues.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2601