## Summary - Implements target 6 of #1316 (egfx fuzz-coverage umbrella): the `egfx_surface_state` state-machine oracle. Sibling of `egfx_multi_frame` (PR #1336) with two distinct properties. - **Narrowed PDU set**: a `SurfaceLifecyclePdu` enum containing the seven variants relevant to surface lifecycle (`ResetGraphics`, `CreateSurface`, `DeleteSurface`, `MapSurfaceToOutput`, `StartFrame`, `EndFrame`, `FrameAcknowledge`), concentrating fuzz pressure on the surface and frame state machine rather than spreading across all 23 `GfxPdu` variants. Two of the seven do not themselves affect modeled state: `FrameAcknowledge` has no arm in the client's receive path, included as legitimate hostile-server input; `StartFrame` is unmodeled since its state lives in private fields with no public getter. - **Parallel state-machine model**: an `ExpectedState` struct mirrors the client's documented per-surface fields (`id`, `width`, `height`, `pixel_format`, `is_mapped`, `output_origin_x/y`) plus the `total_frames_decoded` counter. For each successfully-encoded PDU the model is updated to mirror the client's `handle_*` transitions; after dispatch the client's observable state via the public `get_surface` and `total_frames_decoded` getters is asserted against the model. ## What this catches A different bug class from `egfx_multi_frame`'s panic / sanitizer oracle: logic bugs in state transitions that produce wrong but non-crashing observable state. Examples: - Client retains a surface after `DeleteSurface` (model removed it, client did not). - Client clobbers `is_mapped` on a surface that did not receive `MapSurfaceToOutput`. - Client fails to clear all surfaces on `ResetGraphics`. - Client increments `total_frames_decoded` on a PDU other than `EndFrame`. The model encodes the implementation's current documented behavior (e.g., `CreateSurface` with `width == 0` or `height == 0` is silently skipped per `handle_create_surface`, `total_frames_decoded` is incremented unconditionally by `handle_end_frame` even when no matching `StartFrame` preceded it). The oracle catches drift from that behavior. Spec-compliance verification is a separate concern. ## What this does NOT catch State transitions that exist only in private fields without a public getter (`current_frame_id`, `frames_queued`). Wiring observable access to those fields is a separate egfx-public-API change, out of scope here. ## Dependencies **This PR is stacked on PR #1336 (`egfx_multi_frame`, target 5) and must merge after it.** The `Arbitrary` cascade both harnesses need landed in #1334, so #1336 is the only remaining ancestor. Both branches are rebased onto current master and green. ## Validation - `cargo xtask check fmt/lints/tests/typos/locks` all pass. - `check_egfx_surface_state` regression-replay test passes against the seed-empty corpus entry. - 15-minute rigorous libFuzzer + ASan fuzz on the final SHA: **2,770,751 iterations in 901 seconds (~3,075 exec/s sustained), peak RSS 102 MB, zero panics, zero sanitizer reports, zero state-model assertion failures.** Corpus grew to ~1,840 entries. ## Notes - The narrowed `SurfaceLifecyclePdu` enum lives oracle-private inside the function (not exported from `ironrdp-egfx`), keeping the egfx public surface clean per the fallback shape from the design discussion on #1316. - The oracle uses `as _` imports for `Arbitrary` and `DvcProcessor` per clippy's `unused_trait_names` lint, matching the `egfx_multi_frame` style. - The `#[expect(clippy::panic, reason = ...)]` and `# Panics` doc section match the precedent from `bulk_round_trip` for assertion-based oracles. With this PR the #1316 umbrella has its initial six target slots filled (1 merged, 2+2b+3+5+6 open). Refs #1316. Depends on #1336. ## Rebase 2026-08-19 Rebased onto current master (was CONFLICTING after the RDPEUDP/RDPEMT series landed). Two conflicts, both purely additive insertions at the same point as unrelated new content master added: - `fuzz/Cargo.toml`: master added 8 new `[[bin]]` entries for the RDPEUDP/RDPEMT fuzz targets at the same list position as this PR's own `egfx_surface_state` entry. Resolved by keeping both sets. - `crates/ironrdp-fuzzing/src/oracles/mod.rs`: same shape, master's 8 new oracle functions plus this PR's own `egfx_surface_state` oracle, both appended at end of file. The automatic merge here needed a manual fix: it dropped the closing braces of master's last function (`rdpeudp_ack_vector`'s oracle), since git's diff3 alignment treated that closing syntax as shared trailing context and attached it only to this PR's block instead of both. Caught by diffing the resolved file against both source commits directly rather than trusting the merge; fixed, then re-verified byte-identical to both sources. No logic in the oracle or the state model changed, so the fuzz run and validation numbers above still describe the actual code; only the commit SHAs changed (rebase, no content edits beyond the two conflict resolutions). All checks re-run on the new head: `cargo xtask check fmt/lints/tests/typos/locks`, a direct `cargo check --all-targets` in the `fuzz/` workspace (not covered by the main gate), and `cargo xtask wasm check`, all green. `fuzz/Cargo.lock` unchanged.
IronRDP fuzzing
Difference between fuzzing and property testing
ironrdp correctness is validated in various ways. Two of these are fuzzing and property testing.
Both of these methods involve feeding random inputs to the API in order to check if the program is
behaving as expected or not.
However,
-
Fuzzing is well suited for black-box-like testing. Inputs are typically guided by instrumentalizing the code (coverage…) rather than manually informed.
-
Property testing requires the developer to describe the interesting inputs and properties to test.
-
When fuzzing, some properties are tested as well, but those are typically simple (absence of crash, round-trip…).
-
In contrast, property testing is well suited when testing more complex properties.
-
With fuzzing, we are actively trying to show that something is (unexpectedly) broken.
-
With property testing, we are actively trying to show that the properties are holding (as expected).
Targets
pdu_decoding
Feeds random inputs to PDU decoding code.
bitmap_stream
Feeds random inputs to the RDP6 bitmap decoder.
rle_decompression
Feeds random inputs to the interleaved Run-Length Encoding (RLE) bitmap decoder.
bulk_mppc
Feeds random inputs to the MPPC bulk decompressor (ironrdp-bulk). The first
input byte selects between RDP4 mode (low bit clear, 8 KB history) and RDP5
mode (low bit set, 64 KB history); remaining bytes are the compressed payload.
bulk_ncrush
Feeds random inputs to the NCRUSH bulk decompressor (RDP6.0, ironrdp-bulk).
bulk_xcrush
Feeds random inputs to the XCRUSH bulk decompressor (RDP6.1, ironrdp-bulk).
XCRUSH has the largest sliding-window history of the bulk family (2 MB).
bulk_round_trip
Compresses arbitrary input via BulkCompressor::compress, then decompresses
the result via BulkCompressor::decompress, and asserts byte-equality with
the original input. First input byte selects the algorithm (RDP4 / RDP5 /
RDP6 / RDP6.1). Catches asymmetric bugs where the compressor produces output
the decompressor cannot consume, or the decompressor produces output that
does not equal the original input.
Building crates with the arbitrary feature
Several crates expose an optional arbitrary feature that enables
arbitrary::Arbitrary implementations on their
PDU types. This is the foundation for structure-aware fuzzing harnesses that
generate valid-looking inputs rather than raw bytes.
To verify the feature compiles cleanly for a single crate:
cargo check -p ironrdp-pdu --features arbitrary
The feature is also compatible with the no_std + alloc build path:
cargo check -p ironrdp-pdu --no-default-features --features arbitrary,alloc
A handful of PDU types do not implement Arbitrary. They fall into two categories:
- Types with non-derivable fields (e.g.,
StaticChannelSetkeyed byTypeId). These are either skipped via#[arbitrary(default)]on the containing struct's field, or hand-rolled with a placeholder. - Error types that are not part of the wire-protocol surface (e.g.,
ServerLicenseError). Most error enums fall here: they are constructed locally rather than decoded from the wire, so the fuzzer has no reason to generate them. The exception is wire-protocol error PDUs such asDisconnectProviderUltimatuminmcs.rs, which do implementArbitrarybecause they are decoded from the wire.
Inline source comments mark each skip with the rationale.