Skip to content

[CTX-0247] feat(rich): kitty payload decode (PNG/RGB, bounded, fuzz-tested) - #425

Merged
Xuepoo merged 1 commit into
mainfrom
carryctx/ctx-0247
Sep 8, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
carryctx/ctx-0247

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Closes #424. Implements CTX-0247 under epic CTX-0246.

Summary

Decodes assembled Kitty graphics payloads (kitty.rs intake unchanged) into owned RGBA8 bitmaps via a new kitty_decode module. Supports the formats terminals actually transmit: f=100 PNG, f=24 raw RGB, f=32 raw RGBA; everything else fails closed. No present/render coupling (CTX-0248), no parser/APC changes.

Decoder-crate justification (why not std-only, why not image)

  • std-only cannot do this: PNG needs DEFLATE decompression plus unfiltering across five filter types, Adam7 deinterlacing, and palette/tRNS/16-bit normalization. Hand-rolling that is a new attack surface of its own.
  • Minimal png (0.18) over the full image facade: no format autodetect, no extra codecs, no color-management stack, no EXIF/TIFF surface. Pulls only bitflags/crc32fast/fdeflate/flate2/miniz_oxide, all already in tree.
  • Zero new supply-chain surface: png 0.18.1 is already in Cargo.lock via arboard; this adds one edge (bitty-rich -> png), no new crates. Licenses (MIT/Apache-2.0) in the cargo-deny allow list.

Bounds (before allocation, checked arithmetic)

8192 px/side, 4096^2 px area, 64 MiB RGBA ceiling (IMG-3 parity, 4x+ headroom under the 320 MiB ledger). IHDR parsed via read_info first; output_buffer_size re-checked; set_limits(64 MiB) + set_ignore_text_chunk(true) as defense in depth. Raw payloads must be exactly w*h*channels; PNG ignores supplied s/v (IHDR governs). Exact RFC admission stays with placement (CTX-0248).

Tests (22 new, in-module)

Real byte vectors (Python-stdlib-generated, CRC-verified): 1x1 RGBA/RGB/gray/gray-alpha, palette, 16-bit; raw RGB/RGBA; oversize-dim and over-area rejects (raw + patched-IHDR PNG); every-prefix truncation sweep; deterministic garbage + PRNG fuzz shape; determinism; Display. Note: png decodes a stream missing only the trailing IEND CRC (consumed chunks all CRC-verified) — the truncation test pins byte-equality there rather than Err.

Verification

  • cargo fmt --all -- --check: clean
  • cargo clippy --workspace --all-targets --locked -- -D warnings: clean
  • cargo test -p bitty-rich --locked: 215 passed (193 existing + 22 new)
  • cargo test --workspace --all-targets --locked: exit 0, all suites 0 failed
  • cargo check --target x86_64-pc-windows-gnu --workspace --all-targets: exit 0
  • actionlint, act -n (ci + codeql), [email protected]: clean
  • cargo deny check bans licenses sources: ok

Risks / follow-ups

  • ctl::tests::control_socketpair_roundtrip_headless_live_instance (bitty-app) flaked twice under full-suite parallelism (global queue + thread races); passes solo and 247/247 with this diff on rerun. Pre-existing isolation issue; decode is never called by bitty-app. Suggest follow-up task.
  • APNG yields first frame only; animation deferred to CTX-0248. Decoder review is CTX-0249.
  • Branch is carryctx/ctx-0247 (carryctx-managed) rather than ctx-0247/feat-*.

Priority: P1 | Area: rich | Labels: feat,area:rich,P1 | Milestone: v0.1.0 | Task: CTX-0247

@Xuepoo Xuepoo added feat Feature area:rich Area: rich presentation labels Sep 8, 2026
@Xuepoo Xuepoo added this to the v0.1.0 milestone Sep 8, 2026
@Xuepoo Xuepoo added the P1 Priority: high label Sep 8, 2026
@Xuepoo
Xuepoo merged commit 0cc82de into main Sep 8, 2026
10 checks passed
@Xuepoo
Xuepoo deleted the carryctx/ctx-0247 branch September 8, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:rich Area: rich presentation feat Feature P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CTX-0247] Kitty gfx: payload decode (PNG/RGB, bounded, fuzz-tested)

1 participant