zakrad d6e1859782
fix(term): avoid divide-by-zero crashes in inline image placement (#7872)
assign_image_to_cells contained two unguarded divisions that could panic
with 'attempt to divide by zero' and take down the pane (and, under the mux,
the pane's reader thread):

1. A Kitty graphics escape requesting a zero-sized placement (eg: an explicit
   w=0/h=0, or a source origin outside the image bounds) yields a
   draw_width/draw_height of 0, used as a divisor when sizing the image.
   This is the case reported in #6344.

2. Displaying a cell-sized image (one without explicit c=/r=) on a pane whose
   pty reported no pixel dimensions makes cell_pixel_width/height 0, which is
   then used as a divisor. A zero pixel size is the default PtySize and is what
   tmux/headless domains report, so a perfectly valid image crashes there.

Guard both: refuse the placement when the drawable region or the cell pixel
size is zero.
The error flows into the existing logging handlers for the Kitty, iTerm and
Sixel paths, so no callers change.
Real GUI panes always have a non-zero pixel size, so valid images are
unaffected.

Adds regression tests for both cases (each panics on main, passes with the
fix) and enables kitty graphics in the test terminal config (off by default)
so the path is exercised.

Closes #6344

---------

Co-authored-by: Benoit de Chezelles <benoit.dechezelles@gmail.com>
2026-06-21 22:45:33 +02:00
..

wezterm-term

This crate provides the core of the virtual terminal emulator implementation used by wezterm. The home for this crate is in the wezterm repo and development is tracked at https://github.com/wezterm/wezterm/.

It is full featured, providing terminal escape sequence parsing, keyboard and mouse input encoding, a model for the screen cells including scrollback, sixel and iTerm2 image support, OSC 8 Hyperlinks and a wide range of terminal cell attributes.

This crate does not provide any kind of gui, nor does it directly manage a PTY; you provide a std::io::Write implementation that could connect to a PTY, and supply bytes to the model via the advance_bytes method.

The entrypoint to the crate is the Terminal struct.

License: MIT