Skip to content

Fix DECSLRM scroll text_used, REP reset, and ?7l VS16 width #8

Closed

Description

@tony

Summary

Differential testing of #2 against live tmux 3.8a and seeded grid-invariant fuzzing uncovered four edge-case state bugs in src/libvt/screen.py and src/libvt/terminal.py: DECSLRM vertical scrolling drops copied text from RowView.text, REP (CSI Ps b) repeats stale characters across cursor moves and charset switches, VS16 (U+FE0F) widens column cols - 1 past grid bounds when DECAWM (?7l) is reset, and DECALN (ESC # 8) leaves DECSTBM and DECOM active.

Reproduction

  1. Scroll text inside DECSLRM (?69h, columns 3..7) onto a blank row:
$ uv run python -c 'from libvt import Terminal; vt = Terminal(rows=4, cols=10); vt.feed(b"\x1b[?69h\x1b[3;7s\x1b[2;3HHELLO\x1b[1S\x1b[?69l"); print(vt.lines)'
  1. Move the cursor or switch G0 to DEC Special Graphics between a printable character and REP (CSI b):
$ uv run python -c 'from libvt import Terminal; vt = Terminal(rows=3, cols=10); vt.feed(b"A\x1b[2;3H\x1b[4b"); vt2 = Terminal(rows=3, cols=10); vt2.feed(b"q\x1b(0\x1b[3b\x1b(B"); print("cup:", vt.lines, "acs:", vt2.lines)'
  1. Feed U+2764 U+FE0F at column 4 of a 5-column grid with autowrap disabled (CSI ? 7 l):
$ uv run python -c 'from libvt import Terminal, display_width; vt = Terminal(rows=2, cols=5); vt.feed(b"\x1b[?7l" + "abcd\u2764\ufe0f".encode()); print(repr(vt.screen[0].text), "width:", display_width(vt.screen[0].text))'

Expected

  • Step 1 prints (' HELLO',) on row 0 and '' on row 1.
  • Step 2 prints cup: ('A',) and acs: ('q',) because non-printable C0, ESC, CSI, OSC, DCS, and APC actions invalidate _last_printed.
  • Step 3 keeps display_width(vt.screen[0].text) <= 5 (refusing 1-to-2 cell widening at cols - 1 when DECAWM is off).
  • DECALN (ESC # 8) resets DECSTBM/DECSLRM margins to full screen, resets DECOM (?6l), and homes the cursor to (0, 0).

Actual

  • Step 1 prints ('', ' ') because Screen.scroll_up() and Screen.scroll_down() update dst_row.used without updating dst_row.text_used, and clear_range() leaves stale text_used on partial-row clears.
  • Step 2 prints cup: ('A', ' AAAA') and acs: ('q───',) because _last_printed is cleared only on reset().
  • Step 3 prints 'abcd❤️' width: 6 on a 5-column screen.
Environment
  • libvt: #2 (feat/v2-architecture, 0.1.0a0)
  • Python: 3.15.0 (unicodedata 17.0.0)
  • Reference tmux: 3.8a (tmux -f /dev/null)
  • OS: Linux x86_64

Proposal

Invariants

The invariants below are load-bearing; everything under Intent is open.

  • For every row r, row.text_used accurately bounds non-blank character data after scroll_up, scroll_down, and partial clear_range, and total display width across 0..cols - 1 never exceeds cols.
  • REP (CSI Ps b) repeats only an immediately preceding graphic character without intervening control, escape, or cursor-movement sequences.
  • DECALN (ESC # 8) resets scroll margins, clears DECOM, clears pending_wrap, and homes the cursor to (0, 0).

Intent (non-binding)

  • Recompute or advance dst_row.text_used in Screen.scroll_up() and Screen.scroll_down() partial-margin paths and tighten _Row.clear_range() when clearing across text_used.
  • Clear self._last_printed = "" on execute, esc_dispatch, csi_dispatch (other than REP itself before reading _last_printed), osc_dispatch, dcs_put/unhook, and apc_dispatch.
  • Guard VS16 cell widening in _try_extend_cluster() when anchor_col == scr.cols - 1 and not self._modes.is_set(Mode.DECAWM).

Not doing

  • Changing VS16 widening when DECAWM (?7h) is enabled and the cluster wraps onto row r + 1 column 0.

References

Activity

  1. added
    bug
    on Nov 22, 2026
  2. tony commented on Nov 23, 2026

    @tony
    MemberAuthor

    Resolved in #2 (0c7ee41).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions