From f6222bc8315bca548b6d9222f0f9da73aad71d7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Alonso?= <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:55:02 +0100 Subject: [PATCH] fix(graphics): ignore a sixel colour in an unknown colour space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #846 Signed-off-by: Álvaro Alonso <242080768+alvaroalonsoparrondo-a11y@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ crates/termlens/src/graphics.rs | 37 +++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 710021d..8b8d69c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,12 @@ reads that marker. ### Fixed +- A sixel colour definition in a colour space other than HLS (`1`) or + RGB (`2`), such as `#1;3;10;20;30`, is ignored and the register keeps + its colour, as xterm does. Decoding failed with `termlens does not + decode sixel HLS colours`, naming a colour space the image did not + use. HLS is still refused. (#846) + - Both published crates, `termlens` and `termlens-cli`, ship `LICENSE-MIT` and `LICENSE-APACHE`. They are `MIT OR Apache-2.0`, and both licences ask for their text in every copy, but the texts sat only at the repository diff --git a/crates/termlens/src/graphics.rs b/crates/termlens/src/graphics.rs index d0f90f1..fa571c6 100644 --- a/crates/termlens/src/graphics.rs +++ b/crates/termlens/src/graphics.rs @@ -888,13 +888,17 @@ fn decode_sixel(data: &[u8], background: Option<(u32, u32)>) -> Result= 5 { - // `#n;1;…` is HLS; only RGB (`2`) is defined here, and a - // guessed conversion would put wrong colours into an - // assertion that reads as exact. - if values[1] != 2 { - return Err(DecodeError::Unsupported("sixel HLS colours")); + match values[1] { + // `#n;1;…` is HLS; only RGB (`2`) is defined here, + // and a guessed conversion would put wrong colours + // into an assertion that reads as exact. + 1 => return Err(DecodeError::Unsupported("sixel HLS colours")), + 2 => registers[index] = rgb([values[2], values[3], values[4]]), + // Any other colour space is a data error to xterm + // (`graphics_sixel.c`), which ignores the definition + // and leaves the register as it was. + _ => {} } - registers[index] = rgb([values[2], values[3], values[4]]); } current = index; } @@ -2898,6 +2902,27 @@ mod tests { )); } + #[cfg(feature = "decode")] + #[test] + fn a_colour_in_an_unknown_space_leaves_the_register_as_it_was() { + // Register 1 is defined blue; colour spaces 3 and 0 are neither + // HLS nor RGB, so xterm ignores both definitions. + for space in [0, 3] { + let data = format!("#1;2;0;0;100#1;{space};10;20;30#1!3~"); + let bitmap = sixel_payload(data.as_bytes()).decode().expect("decodes"); + assert_eq!( + bitmap.colours(), + vec![([0, 0, 255, 255], 18)], + "space {space}" + ); + } + // Undefined before, the register keeps its VT340 default. + let bitmap = sixel_payload(b"#1;3;10;20;30#1!3~") + .decode() + .expect("decodes"); + assert_eq!(bitmap.colours(), vec![([51, 51, 204, 255], 18)]); + } + #[test] fn the_debug_rendering_stays_short_enough_for_a_log() { let payload = kitty_payload(b"a=T,f=32,o=z,s=954,v=133,i=7,c=106,r=7", &[b'A'; 4096]);