szn

Bug 548 — Sixel DCS parameters (P1;P2;P3) stripped by InputParser and unclamped raster-free px_height

548. advanceDcsParam drops P1;P2;P3 before 'q' and dispatchDcsSixel leaves fallback px_height unclamped

Severity: MEDIUM
Status: ✅ RESOLVED
Files: src/input.zig:436-454, src/input.zig:600-607

Problem

  1. DCS parameters (P1;P2;P3) discarded (src/input.zig:436-454):
    fn advanceDcsParam(self: *InputParser, byte: u8) Error!void {
        switch (byte) {
            0x30...0x3B => {},
            'q' => {
                self.dcs_buf.clearRetainingCapacity();
                try self.dcs_buf.appendSlice(self.screen.allocator, "\x1bPq");
                self.state = .dcs_sixel;
            },
    

    A DECSIXEL introducer has the form ESC P P1 ; P2 ; P3 q, where P2 = 1 selects a transparent background (leaves zero-valued sixel pixels at their current screen color instead of filling the bounding box with background color 0) and P1/P3 control aspect ratio and horizontal grid size. Because 0x30...0x3B is a no-op and "\x1bPq" is hardcoded, all sixel images lose transparency (P2=1) when rendered through szn.

  2. Unclamped fallback px_height in dispatchDcsSixel (src/input.zig:600-607): When a sixel stream omits the "Pan;Pad;Ph;Pv raster header, parseSixelDimensions computes px_height from bands * 6:
    if (px_height == 0) {
        px_height = bands * 6;
        if (px_height == 0) px_height = 6;
    }
    

    Unlike the raster header path (which clamps pv to MAX_SIXEL_DIM = 16384), bands * 6 is neither saturating (*|) nor clamped to MAX_SIXEL_DIM.

Proposed Fix

  1. Buffer DCS parameter bytes (bounded to e.g. 16 bytes) after ESC P / 0x90, and when 'q' arrives with empty intermediate bytes, emit "\x1bP" ++ params ++ "q" into self.dcs_buf.
  2. In parseSixelDimensions, compute px_height = @min(bands *| 6, MAX_SIXEL_DIM).