Skip to content

terminal: fix crash after shrinking columns splits a wide char - #14509

Merged
mitchellh merged 1 commit into
ghostty-org:mainfrom
fornwall:wide-head
Oct 4, 2026
Merged

mitchellh merged 1 commit into
ghostty-org:mainfrom
fornwall:wide-head

Conversation

@fornwall

@fornwall fornwall commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Narrowing the terminal without reflow (wraparound off, or the alternate screen) can cut a wide char in half, leaving its head in the last column with no spacer tail.

Later edits on that row (e.g. ICH) then clear the missing tail too, reaching one cell past the row end, which leads to a bounds assertion failure in safe builds or an out-of-bounds write otherwise.

To reproduce, run the below script inside a safe build:

#!/bin/sh
printf '\e[?40h\e[?3h'       # allow DECCOLM, switch to 132 columns
printf '\e[?47h\e[1;80H一'   # alternate screen: wide char in columns 80-81
printf '\e[?47l\e[?3l'       # back to 80 columns (alternate screen shrinks without reflow)
printf '\e[?47h\e[1;80H\e[@' # alternate screen: insert a blank at the last column
printf '\e[2;1Hsurvived\n'
  • Before: Triggers assertion in Screen.clearCells.
  • After: Prints survived, column 80 is blank.

AI disclosure: Created with claude code using opus 5.5. Iterated on and reviewed by me.

@ghostty-bot ghostty-bot Bot added the vt Control sequence related label Oct 1, 2026
@fornwall
fornwall requested a review from a team as a code owner October 1, 2026 21:15
@fornwall fornwall changed the title terminal: clear wide char cut by a non-reflow narrowing terminal: fix crash after shrinking columns splits a wide char Oct 4, 2026
Narrowing without reflow cleared only the cells past the new width, so a
wide char whose spacer tail was cut kept its head in the new last column.
Every operation pairing a head with the cell after it then reached past
the row end: insertBlanks and eraseLine(.left) panic in Screen.clearCells,
and rowWillBeShifted writes cells[cols].

Clear the orphaned head along with the cut columns.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>
@mitchellh
mitchellh enabled auto-merge October 4, 2026 13:03
@mitchellh
mitchellh merged commit 5dc28bb into ghostty-org:main Oct 4, 2026
@github-actions github-actions Bot added this to the 1.4.0 milestone Oct 4, 2026
@fornwall
fornwall deleted the wide-head branch October 4, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

vt Control sequence related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants