Commit 59b3de3
committed
feat(pdu,graphics): add ClearCodec bitmap compression codec
Add ClearCodec (MS-RDPEGFX 2.2.4.1) codec support across two crates:
ironrdp-pdu: Wire-format decode/encode for all ClearCodec layers
(residual BGR RLE, bands with V-bar caching, subcodec dispatch
including RLEX palette-indexed RLE). Full round-trip test coverage.
ironrdp-graphics: ClearCodecDecoder with persistent V-bar and glyph
caches. ClearCodecEncoder with residual-only encoding and glyph
deduplication for server-side bitmap compression.
Hardening pass before maintainer review (local fuzz oracles surfaced
three bug classes that escaped the initial review):
- Per-dimension cap at 8192 on decode, replacing the previous per-
pixel-count cap at 8192*8192. The pixel-count form accepted
degenerate aspect ratios (e.g. 63961x771 = 49M pixels, under the
67M cap) that allocated ~197MB from a few attacker-controlled
bytes. The per-dimension form rejects implausible tile shapes
regardless of total area while preserving headroom for 8K
displays (7680x4320). MS-RDPEGFX caps surfaces at 32767x32767
but does not mandate a separate tile cap; 8192 is a defensive
choice that fits realistic tile sizes.
- Fix integer overflow at bands::decode_band on
`usize::from(x_end - x_start + 1)`. When x_end = u16::MAX and
x_start = 0, the `+ 1` overflowed the u16 arithmetic before the
usize cast and triggered a release-mode panic under
overflow-checks. The existing `if x_end < x_start` guard
prevents underflow but not the +1 overflow. Fix is to cast to
usize first: `usize::from(x_end - x_start) + 1`.
- Document the alpha contract on ClearCodecEncoder::encode and
ClearCodecDecoder::decode. ClearCodec is lossless on the three
color channels (B, G, R) per spec; the wire format does not
transmit alpha. The encoder reads B/G/R from each input pixel
and discards alpha; the decoder fills alpha with 0xFF
unconditionally. Callers needing alpha must transport it
separately. Previously the doc-comment claim of "pixel-perfect
fidelity" was ambiguous; alpha-channel mismatches in any
round-trip with non-0xFF alpha inputs are by design, not bugs.
Local fuzz infrastructure (clearcodec_decode + clearcodec_round_trip
oracles) follows in a separate PR once this lands; the codec's
public API is already fuzz-friendly so no prep is needed here.
A separate spec-driven audit of input-validation completeness
(per-layer stream-length pre-checks in subcodec / residual /
bands) is queued as follow-up work; deferring from this PR pending
review of MS-RDPEGFX 2.2.4.1.
Closes #1158 ClearCodec subtask.1 parent 879ffed commit 59b3de3
12 files changed
Lines changed: 2657 additions & 0 deletions
File tree
- crates
- ironrdp-graphics/src
- clearcodec
- ironrdp-pdu/src/codecs
- clearcodec
- ironrdp-testsuite-core/tests/graphics
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
0 commit comments