Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

fix(term): accept unpadded Kitty graphics payloads

RoversX595b30bc58b5
diff --git a/docs/thinkterm/kitty-base64-compatibility.md b/docs/thinkterm/kitty-base64-compatibility.md
new file mode 100644
index 00000000..a2c0e6ae
--- /dev/null
+++ b/docs/thinkterm/kitty-base64-compatibility.md
@@ -0,0 +1,79 @@
+# Kitty Base64 compatibility
+
+Kitten 0.49.0's Images benchmark used to log `base64_decode: Invalid padding`
+and discard each image in ThinkTerm. Kitty's [Go graphics sender](https://github.com/kovidgoyal/kitty/blob/master/tools/tui/graphics/command.go)
+uses `RawStdEncoding`, which omits trailing `=` characters. ThinkTerm's decoder
+required them when the raw byte count was not divisible by three.
+
+## Change
+
+Kitty pixel payloads, file paths, temporary-file paths, and shared-memory names
+now accept either canonical padding or no padding. The decoder checks the last
+byte to choose the mode before allocating its output. Each chunk is decoded
+once, without copying the input, appending padding, or concatenating/retrying
+the transfer. Path/name decoding also drops the previous temporary input copy.
+
+Malformed padding, invalid characters, and impossible Base64 lengths still
+fail. Existing tolerance for unused trailing bits is preserved. OSC clipboard,
+user-variable, and iTerm decoding retain their original policy. The chunk/byte
+limits, image-store budget, decompression cap, external-file restrictions,
+cleanup, and rendering paths are unchanged. No dependency, cache, or unsafe
+code was added.
+
+## Validation on 2026-09-23
+
+The new small-image regression failed before the fix with `Invalid padding`.
+After the fix, the escape-parser and terminal suites passed (81 + 118 tests).
+The new coverage checks padded/unpadded payload lengths, external-source names,
+malformed inputs, unchanged OSC policy, exact decoded pixels, placement, a bad
+transfer followed by a good one, and image memory accounting after deletion.
+The large regression sends a 1024x1024 RGBA image in 128 KiB Base64 chunks and
+splits those chunks across PTY-sized reads, then compares all 4 MiB of pixels.
+
+On an M1 Pro, an isolated release mux received 100 uncompressed 4 MiB images per
+run, with three warmups. Each transfer waited for its own successful Kitty ACK
+before deletion and the next transfer. The byte content was identical between
+the padded and unpadded cases. Three runs per case, with baseline/candidate
+order varied, gave these medians:
+
+| Case | Encoded wire throughput (decimal MB/s) | Peak mux RSS (MiB) |
+| --- | ---: | ---: |
+| Before, padded | 95.49 | 41.11 |
+| Fixed, padded | 95.48 | 41.13 |
+| Fixed, unpadded | 97.96 | 42.61 |
+
+All transfers were acknowledged. The baseline binary is the parser-optimized
+binary already recorded in `parser-throughput-results.json`; intervening GUI
+recording-mask changes do not affect this mux workload. Both binaries used the
+repository's Cargo release profile. Each mux used a temporary config/socket and
+a macOS sandbox denying writes to existing user settings/session files. Builds
+and test suites were stopped during measurement. These short runs show no
+material regression for previously working padded input; they are not a leak
+test or a GUI/GPU memory measurement.
+
+A separate allocator-counting harness used the old and new decoder functions
+extracted from the source. For raw payloads of 16 B, 4 KiB, 96 KiB, and 4 MiB,
+each decode performed one allocation, zero reallocations, identical peak output
+allocation sizes, and released all measured bytes. The fixed decoder's padded
+input times stayed within about 1.2% of the old decoder over seven interleaved
+rounds. This is a codec microbenchmark, separate from mux throughput. The sample
+external path went from two allocations to one.
+
+The original `kitten __benchmark__ --repetitions 100 images` also completed on
+the fixed isolated mux: 2.08 s, 256.9 MiB/s (kitten labels this MB/s), zero image
+decode errors, and 47.36 MiB peak RSS. It runs asynchronously without a per-image
+ACK, so its number is not comparable to the ACK-paced table. Earlier scores
+from rejected images cannot be used as the performance baseline for this fix.
+Individual measurements and binary hashes are in [the results JSON](kitty-base64-results.json).
+
+```sh
+cargo test --offline -p wezterm-term -p wezterm-escape-parser --features wezterm-escape-parser/kitty-shm
+cargo check --offline -p wezterm-escape-parser --no-default-features --target wasm32-unknown-unknown
+cargo build --offline --release -p wezterm-gui -p wezterm-mux-server
+```
+
+The native release builds for GUI and mux, and the WASM parser check above,
+passed. Shared-memory tests need permission to create their test POSIX
+shared-memory objects. The installed application and active user sessions were not replaced
+or restarted. Foreground GUI visual QA and native Windows execution were not
+performed; pixel content and placement were checked in the terminal model.
diff --git a/docs/thinkterm/kitty-base64-results.json b/docs/thinkterm/kitty-base64-results.json
new file mode 100644
index 00000000..85694514
--- /dev/null
+++ b/docs/thinkterm/kitty-base64-results.json
@@ -0,0 +1,253 @@
+{
+ "date": "2026-09-23",
+ "platform": "macOS, Apple M1 Pro, 16 GiB RAM",
+ "kitten": "0.49.0",
+ "source_base": "1f3b385",
+ "baseline_binary": "pre-fix parser-optimized binary recorded in parser-throughput-results.json",
+ "baseline_sha256": "98d5209cd4a41b4a1f9cf78f48d9b88592811f35c49ddaeaf0f0307e8f61d186",
+ "candidate_mux_sha256": "73a5230c893e32d1266a5fa6ddafb0c59440ae02c867656ec7edc81fbe5bede7",
+ "acknowledged_image_runs": {
+ "baseline-padded": {
+ "runs": [
+ {
+ "mode": "padded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.8570589589944575,
+ "raw_MB_s": 71.61109405530178,
+ "wire_MB_s": 95.4886409571021,
+ "peak_rss_bytes": 44744704,
+ "image_decode_errors": 0
+ },
+ {
+ "mode": "padded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.878601208009059,
+ "raw_MB_s": 71.3486738016119,
+ "wire_MB_s": 95.13872096614215,
+ "peak_rss_bytes": 43073536,
+ "image_decode_errors": 0
+ },
+ {
+ "mode": "padded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.846534666023217,
+ "raw_MB_s": 71.74000052330048,
+ "wire_MB_s": 95.6605291764089,
+ "peak_rss_bytes": 43106304,
+ "image_decode_errors": 0
+ }
+ ],
+ "median_raw_MB_s": 71.61109405530178,
+ "median_wire_MB_s": 95.4886409571021,
+ "median_peak_rss_MiB": 41.109375
+ },
+ "candidate-padded": {
+ "runs": [
+ {
+ "mode": "padded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.857583500008332,
+ "raw_MB_s": 71.60468135015121,
+ "wire_MB_s": 95.48009004040736,
+ "peak_rss_bytes": 46350336,
+ "image_decode_errors": 0
+ },
+ {
+ "mode": "padded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.905526874994393,
+ "raw_MB_s": 71.02336656462988,
+ "wire_MB_s": 94.7049453568918,
+ "peak_rss_bytes": 41500672,
+ "image_decode_errors": 0
+ },
+ {
+ "mode": "padded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.8320097499818075,
+ "raw_MB_s": 71.91867263275894,
+ "wire_MB_s": 95.89877657556121,
+ "peak_rss_bytes": 43122688,
+ "image_decode_errors": 0
+ }
+ ],
+ "median_raw_MB_s": 71.60468135015121,
+ "median_wire_MB_s": 95.48009004040736,
+ "median_peak_rss_MiB": 41.125
+ },
+ "candidate-unpadded": {
+ "runs": [
+ {
+ "mode": "unpadded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.933669000020018,
+ "raw_MB_s": 70.68651790293409,
+ "wire_MB_s": 94.25574631785379,
+ "peak_rss_bytes": 43548672,
+ "image_decode_errors": 0
+ },
+ {
+ "mode": "unpadded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.709387707989663,
+ "raw_MB_s": 73.4632891392282,
+ "wire_MB_s": 97.95838513775224,
+ "peak_rss_bytes": 46284800,
+ "image_decode_errors": 0
+ },
+ {
+ "mode": "unpadded",
+ "images": 100,
+ "acknowledged": 100,
+ "elapsed_seconds": 5.702241332997801,
+ "raw_MB_s": 73.55535753508624,
+ "wire_MB_s": 98.08115218897133,
+ "peak_rss_bytes": 44679168,
+ "image_decode_errors": 0
+ }
+ ],
+ "median_raw_MB_s": 73.4632891392282,
+ "median_wire_MB_s": 97.95838513775224,
+ "median_peak_rss_MiB": 42.609375
+ }
+ },
+ "codec_allocations": [
+ {
+ "case": "old_padded_16",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 18,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_padded_16",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 18,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_unpadded_16",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 18,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "old_padded_4096",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 4098,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_padded_4096",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 4098,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_unpadded_4096",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 4098,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "old_padded_98304",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 98304,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_padded_98304",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 98304,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_unpadded_98304",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 98304,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "old_padded_4194304",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 4194306,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_padded_4194304",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 4194306,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_unpadded_4194304",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 4194306,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "old_path",
+ "allocations": 2,
+ "reallocations": 0,
+ "peak_bytes": 56,
+ "remaining_bytes": 0
+ },
+ {
+ "case": "fixed_path",
+ "allocations": 1,
+ "reallocations": 0,
+ "peak_bytes": 24,
+ "remaining_bytes": 0
+ }
+ ],
+ "codec_seven_round_median_time_ratios": [
+ {
+ "raw_bytes": 16,
+ "fixed_padded_time_ratio": 0.9888426213213785,
+ "fixed_unpadded_time_ratio": 0.6090928996777142
+ },
+ {
+ "raw_bytes": 4096,
+ "fixed_padded_time_ratio": 1.0007646867774511,
+ "fixed_unpadded_time_ratio": 0.988075121460067
+ },
+ {
+ "raw_bytes": 98304,
+ "fixed_padded_time_ratio": 0.9914003790859816,
+ "fixed_unpadded_time_ratio": 0.9950064843654742
+ },
+ {
+ "raw_bytes": 4194304,
+ "fixed_padded_time_ratio": 0.997513726108968,
+ "fixed_unpadded_time_ratio": 1.0009278024195318
+ }
+ ],
+ "kitten_images_smoke": {
+ "repetitions": 100,
+ "elapsed_seconds_reported": 2.08,
+ "reported_MiB_s": 256.9,
+ "peak_rss_bytes": 49659904,
+ "image_errors": 0,
+ "padding_errors": 0,
+ "exit_code": 0
+ }
+}
diff --git a/docs/thinkterm/parser-throughput.md b/docs/thinkterm/parser-throughput.md
index 88bf77fb..e582ce0c 100644
--- a/docs/thinkterm/parser-throughput.md
+++ b/docs/thinkterm/parser-throughput.md
@@ -50,7 +50,9 @@ in these workloads; they are not a long-duration leak test or GUI/GPU memory mea
optimized binaries both logged `Invalid padding` while decoding the benchmark
images. Their roughly 278 MiB/s scores measure a rejected transfer, not successful
image processing. This pre-existing compatibility issue is separate from the
-text/CSI changes and remains unresolved.
+text/CSI changes. A subsequent [Kitty Base64 fix](kitty-base64-compatibility.md)
+accepts unpadded payloads; the historical rejected-transfer scores above remain
+excluded.
The benchmark waits for terminal status replies after parsing. These results do
not establish foreground frame rate, input latency, or the cost of synchronizing
diff --git a/term/src/test/graphics.rs b/term/src/test/graphics.rs
index d52d78f0..c6bbf2eb 100644
--- a/term/src/test/graphics.rs
+++ b/term/src/test/graphics.rs
@@ -226,6 +226,119 @@ fn sixel_still_works_on_a_normal_pane() {
/// Half of a 2x2 RGBA image, base64 encoded: eight zero bytes.
const HALF_2X2: &str = "AAAAAAAAAAA=";
+#[test]
+fn an_unpadded_kitty_image_is_decoded_and_placed() {
+ use wezterm_cell::image::ImageDataType;
+
+ let (mut term, tap) = term_with_tap(640, 384);
+ let pixels = [
+ 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255, 255, 255, 255, 255,
+ ];
+ let encoded = base64_of(&pixels);
+ term.advance_bytes(format!(
+ "\x1b_Ga=T,i=9,f=32,s=2,v=2,c=1,r=1;{}\x1b\\",
+ encoded.trim_end_matches('=')
+ ));
+ assert_eq!(drain(&mut term, &tap), "\x1b_Gi=9;OK\x1b\\");
+ let image = term.kitty_image_data_for_id(9).expect("decoded image");
+ match &*image.data() {
+ ImageDataType::Rgba8 {
+ data,
+ width,
+ height,
+ ..
+ } => {
+ assert_eq!((*width, *height), (2, 2));
+ assert_eq!(data.as_slice(), pixels.as_slice());
+ }
+ other => panic!("unexpected image data {:?}", other),
+ }
+ assert!(term
+ .screen_mut()
+ .line_mut(0)
+ .get_cell(0)
+ .unwrap()
+ .attrs()
+ .images()
+ .unwrap()
+ .iter()
+ .any(|im| im.image_id() == Some(9)));
+ assert_eq!(term.kitty_used_memory(), pixels.len());
+ drop(image);
+ term.advance_bytes("\x1b_Ga=d,d=I,i=9\x1b\\");
+ assert!(term.kitty_image_data_for_id(9).is_none());
+ assert_eq!(term.kitty_used_memory(), 0);
+}
+
+#[test]
+fn benchmark_sized_kitty_images_decode_with_optional_padding() {
+ use wezterm_cell::image::ImageDataType;
+
+ let (mut term, tap) = term_with_tap(640, 384);
+ let pixels: Vec<u8> = (0..4 * 1024 * 1024).map(|i| (i % 251) as u8).collect();
+ let padded = base64_of(&pixels);
+ // kitten __benchmark__ sends a 1024x1024 RGBA image in 128 KiB
+ // Base64 chunks, with no '=' in the final chunk. Check the old padded
+ // form too, including deleting the stored image after each transfer.
+ for encoded in [padded.as_str(), padded.trim_end_matches('=')] {
+ let mut chunks = encoded.as_bytes().chunks(128 * 1024).peekable();
+ let mut first = true;
+ while let Some(chunk) = chunks.next() {
+ let more = u8::from(chunks.peek().is_some());
+ let header = if first {
+ first = false;
+ format!("\x1b_Ga=t,i=12345,f=32,s=1024,v=1024,m={more};")
+ } else {
+ format!("\x1b_Gm={more};")
+ };
+ term.advance_bytes(header);
+ // Also split PTY reads inside the APC payload.
+ for bytes in chunk.chunks(8191) {
+ term.advance_bytes(bytes);
+ }
+ term.advance_bytes("\x1b\\");
+ }
+ assert_eq!(drain(&mut term, &tap), "\x1b_Gi=12345;OK\x1b\\");
+ // Tap retains replies, including the sentinel. Start the next
+ // transfer with an empty buffer so drain waits for its own reply.
+ tap.0.lock().unwrap().clear();
+ let image = term.kitty_image_data_for_id(12345).expect("complete image");
+ match &*image.data() {
+ ImageDataType::Rgba8 {
+ data,
+ width,
+ height,
+ ..
+ } => {
+ assert_eq!((*width, *height), (1024, 1024));
+ assert_eq!(data, &pixels);
+ }
+ other => panic!("unexpected image data {:?}", other),
+ }
+ assert_eq!(term.kitty_used_memory(), pixels.len());
+ drop(image);
+ term.advance_bytes("\x1b_Ga=d,d=I,i=12345\x1b\\");
+ assert!(term.kitty_image_data_for_id(12345).is_none());
+ assert_eq!(term.kitty_used_memory(), 0);
+ }
+}
+
+#[test]
+fn a_malformed_kitty_tail_does_not_poison_the_next_image() {
+ let (mut term, tap) = term_with_tap(640, 384);
+ term.advance_bytes("\x1b_Ga=t,i=9,f=32,s=2,v=2,m=1;AAAAAAAAAAAAAAAA\x1b\\");
+ // Four more bytes need either no padding or two '=' characters.
+ term.advance_bytes("\x1b_Gm=0;AAAAAA=\x1b\\");
+ assert!(term.kitty_image_data_for_id(9).is_none());
+ assert_eq!(term.kitty_used_memory(), 0);
+ term.advance_bytes("\x1b_Ga=t,i=10,f=32,s=2,v=2;AAAAAAAAAAAAAAAAAAAAAA\x1b\\");
+ let reply = drain(&mut term, &tap);
+ assert!(reply.contains("i=10;OK"), "{:?}", reply);
+ assert!(!reply.contains("i=9;OK"), "{:?}", reply);
+ assert!(term.kitty_image_data_for_id(10).is_some());
+ assert_eq!(term.kitty_used_memory(), 16);
+}
+
#[test]
fn a_chunked_transfer_reassembles() {
let (mut term, _tap) = term_with_tap(640, 384);
diff --git a/wezterm-escape-parser/src/apc.rs b/wezterm-escape-parser/src/apc.rs
index 9b07952e..882b0f27 100644
--- a/wezterm-escape-parser/src/apc.rs
+++ b/wezterm-escape-parser/src/apc.rs
@@ -2,6 +2,28 @@ use crate::allocate::*;
use crate::osc::{base64_decode, base64_encode};
use core::fmt::{Display, Error as FmtError, Formatter};
+/// Kitty's Go clients omit Base64 padding for both pixels and external-source
+/// names. Choose the decoder before allocating: don't copy/add padding or
+/// retry a failed decode. Explicit padding must still be canonical.
+fn kitty_base64_decode(data: &[u8]) -> crate::Result<Vec<u8>> {
+ use base64::Engine;
+ use base64::engine::{DecodePaddingMode, GeneralPurpose, GeneralPurposeConfig};
+
+ if data.last() == Some(&b'=') {
+ return base64_decode(data);
+ }
+
+ const UNPADDED: GeneralPurpose = GeneralPurpose::new(
+ &base64::alphabet::STANDARD,
+ GeneralPurposeConfig::new()
+ .with_decode_allow_trailing_bits(true)
+ .with_decode_padding_mode(DecodePaddingMode::RequireNone),
+ );
+ UNPADDED
+ .decode(data)
+ .map_err(|err| crate::format_err!("base64_decode: {:#}", err))
+}
+
fn get<'a>(keys: &BTreeMap<&str, &'a str>, k: &str) -> Option<&'a str> {
keys.get(k).map(|&s| s)
}
@@ -125,17 +147,17 @@ impl KittyImageData {
match t {
"d" => Some(Self::Direct(String::from_utf8(payload.to_vec()).ok()?)),
"f" => Some(Self::File {
- path: String::from_utf8(base64_decode(payload.to_vec()).ok()?).ok()?,
+ path: String::from_utf8(kitty_base64_decode(payload).ok()?).ok()?,
data_size: geti(keys, "S"),
data_offset: geti(keys, "O"),
}),
"t" => Some(Self::TemporaryFile {
- path: String::from_utf8(base64_decode(payload.to_vec()).ok()?).ok()?,
+ path: String::from_utf8(kitty_base64_decode(payload).ok()?).ok()?,
data_size: geti(keys, "S"),
data_offset: geti(keys, "O"),
}),
"s" => Some(Self::SharedMem {
- name: String::from_utf8(base64_decode(payload.to_vec()).ok()?).ok()?,
+ name: String::from_utf8(kitty_base64_decode(payload).ok()?).ok()?,
data_size: geti(keys, "S"),
data_offset: geti(keys, "O"),
}),
@@ -245,7 +267,7 @@ impl KittyImageData {
#[cfg(feature = "kitty-shm")]
fn load_data_capped(self, cap: u64) -> std::io::Result<Vec<u8>> {
match self {
- Self::Direct(data) => base64_decode(data).or_else(|err| {
+ Self::Direct(data) => kitty_base64_decode(data.as_bytes()).or_else(|err| {
Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!("base64 decode: {err:#}"),
@@ -1678,6 +1700,109 @@ mod test {
use super::*;
use k9::assert_equal as assert_eq;
+ #[cfg(feature = "kitty-shm")]
+ #[test]
+ fn kitty_payload_accepts_optional_base64_padding() {
+ for len in 0..65 {
+ let bytes: Vec<u8> = (0..len).map(|i| (i * 37) as u8).collect();
+ let padded = base64_encode(&bytes);
+ for encoded in [padded.as_str(), padded.trim_end_matches('=')] {
+ assert_eq!(
+ KittyImageData::Direct(encoded.to_string())
+ .load_data()
+ .unwrap(),
+ bytes
+ );
+ }
+ }
+ // Preserve the existing tolerance for unused low bits in the last
+ // symbol; this change only makes trailing '=' optional for Kitty.
+ for encoded in ["Zh==", "Zh"] {
+ assert_eq!(
+ KittyImageData::Direct(encoded.to_string())
+ .load_data()
+ .unwrap(),
+ b"f".to_vec()
+ );
+ }
+ // OSC clipboard/user-variable/iTerm decoding keeps its own policy.
+ assert!(crate::osc::base64_decode("Zg").is_err());
+ }
+
+ #[cfg(feature = "kitty-shm")]
+ #[test]
+ fn kitty_payload_rejects_malformed_base64() {
+ for encoded in [
+ "A",
+ "YWJjA",
+ "YQ=",
+ "YQ===",
+ "YQ====",
+ "=YQ=",
+ "Y=Q=",
+ "YQ==Yg==",
+ "YQ$=",
+ "YQ\n",
+ "YQ ",
+ "YQ-_",
+ "YQ\u{00ff}",
+ ] {
+ let err = KittyImageData::Direct(encoded.to_string())
+ .load_data()
+ .expect_err(encoded);
+ assert_eq!(err.kind(), std::io::ErrorKind::InvalidInput);
+ }
+ }
+
+ #[test]
+ fn kitty_external_names_accept_optional_base64_padding() {
+ // File paths and shared-memory names use the same Kitty wire
+ // encoding. Parsing these commands must not open/delete anything.
+ for name in ["/x", "/xy", "/xyz"] {
+ let padded = base64_encode(name);
+ for encoded in [padded.as_str(), padded.trim_end_matches('=')] {
+ for transport in ["f", "t", "s"] {
+ let command = format!("Ga=t,t={transport},S=4,O=1;{encoded}");
+ let Some(KittyImage::TransmitData { transmit, .. }) =
+ KittyImage::parse_apc(command.as_bytes())
+ else {
+ panic!("failed to parse {command}");
+ };
+ match transmit.data {
+ KittyImageData::File {
+ path,
+ data_size,
+ data_offset,
+ }
+ | KittyImageData::TemporaryFile {
+ path,
+ data_size,
+ data_offset,
+ }
+ | KittyImageData::SharedMem {
+ name: path,
+ data_size,
+ data_offset,
+ } => {
+ assert_eq!(path, name);
+ assert_eq!(data_size, Some(4));
+ assert_eq!(data_offset, Some(1));
+ }
+ other => panic!("unexpected transport {other:?}"),
+ }
+ }
+ }
+ }
+ for transport in ["f", "t", "s"] {
+ for invalid in ["Lw=", "L3g$", "L3g==="] {
+ assert!(
+ KittyImage::parse_apc(format!("Ga=t,t={transport};{invalid}").as_bytes())
+ .is_none()
+ );
+ }
+ }
+ }
+
#[test]
fn kitty_payload() {
assert_eq!(