This document specifies the structural domain (UBE) adapters for format_name = "WAV" and "WEBP". Common definitions for envelopes, trailers, AAD, offset_delta, and strategy IDs are defined in STRUCTURE-ENVELOPE.md §2–§15; this document focuses on RIFF container detection, strategy selection, chunk layout, capacity, and cover restoration. Content domain steganography (WAV PCM LSB / FLAC residuals) is defined in CONTENT-AUDIO.md; the two domains are mutually exclusive and non-interchangeable.
Carriers are WAVE or WEBP containers starting with a 12-byte RIFF header. Adapters operate strictly on top-level chunk streams: no PCM audio decoding, no WebP image decoding, and no re-encoding; envelopes are appended exclusively as newly constructed top-level chunks.
| Tier | RIFF Structural Scope |
|---|---|
| F |
"RIFF" + u32le size + form type (WAVE / WEBP); chunk identifier "SHRD"; chunk length field u32le; 8-byte chunk header prepended to UBE; append at physical EOF; 1-byte 0x00 padding on odd byte counts; riff_chunk parameters: |
| D | Carrier branching: WebP Extended Format (first chunk following 12B header is VP8X) permits riff_chunk, while Simple Format allows eof only; whether declared RIFF boundary equals physical EOF and whether chunk tables span the boundary precisely determine riff_chunk availability; UBE oddness dictates padding byte |
| I | Copy buffering / streaming methods, scanner implementation, strategy_note phrasing, error messages, auto predicate invocation frequency; readers depend on none of these |
Difference from Content Domain WAV/FLAC: Structural domain operations append a RIFF chunk, leaving PCM samples inside data and FLAC residual frames byte-for-byte untouched; PCM LSB and residual mutations belong to CONTENT-AUDIO.md.
detect inspects the first 12 bytes exclusively: buf[0..4] == "RIFF" and buf[8..12] equals the expected form type (b"WAVE" for WAV, b"WEBP" for WebP), returning true on match and false otherwise without raising errors, restoring stream position before returning (rust/src/structure/adapters/riff.rs:13-31, wav.rs:18, webp.rs:18). It does not validate the size field, chunk table, minimum file length, or WebP VP8X. Registration evaluates in registry.rs:25-36 order (WEBP precedes WAV), with distinct form types preventing misclassification.
Structural validation gates occur during pre-write verification and injection:
- File length
$< 12 \to \text{CorruptedData}("\text{ file too small for a valid RIFF header}")$ (riff.rs:62-68). -
$host_len \ne 8 + old_riff_size$ (streaming WAV with size 0 or0xFFFFFFFF, trailing garbage)$\to$ CorruptedData, prompting switch to--strategy eof(riff.rs:93-99). - Chunk table does not span declared boundary precisely
$\to$ CorruptedData; trailing odd-length chunk missing pad returnsMissingFinalPad(riff.rs:107-121,:389-446). - WebP Simple Format explicitly requesting
riff_chunk$\to$ UnsupportedFormat, prompting switch to--strategy eof(webp.rs:53-68). - Pre-write checks enforce Tier 1 prerequisites: WAV requires
fmtanddatachunks; WebP requires one ofVP8,VP8L, orVP8X(wav.rs:77-85,webp.rs:96-104,engine.rs:1027-1035).
| Strategy | strategy_id |
Behavior | Reference |
|---|---|---|---|
riff_chunk |
10 | Appends a new SHRD top-level chunk at physical EOF with UBE as chunk data |
registry.rs:90-104; riff.rs:81-161 |
eof |
1 | Appends UBE after EOF without modifying RIFF headers | registry.rs:91; riff.rs:73-78 |
Both adapters list ["riff_chunk", "eof"] in order of precedence (wav.rs:21-23, webp.rs:21-23). auto resolution rules:
- WAV: If
riff_can_chunk(reader, ube_size)is true, selectriff_chunk; otherwise selecteof(wav.rs:25-35). - WebP: If the first chunk following 12B header is
VP8Xandriff_can_chunkis true, selectriff_chunk; otherwise selecteof(webp.rs:25-36).
riff_can_chunk enforces injection requirements: Exact, and riff.rs:454-479). riff_chunk always causes the file to expand.
Capacity reporting (riff.rs:520-560): Under dynamic inspection (reader != None), riff_chunk reports actual usable headroom riff.rs:483-503); if this headroom falls below min_ube_len(0), it sets available = false, capacity_bytes = None, noting fallback to eof (riff.rs:506-518, :546-556). Under static inspection (reader == None), it reports capacity_bytes = None and limit = "up to 4GB RIFF limit (file grows)"; eof is unbounded. inspect clamps both to the engine ceiling engine.rs:1938-1975, :2604-2611), omitting values when available = false.
Offset inject_offset = host_len (Original Physical EOF)
+0 "SHRD" (53 48 52 44)
+4 u32le chunk_size = ube_total_size
+8 UBE[0 .. ube_total_size) ← offset_delta = 8
+8+ube_total_size 0x00 (Only if ube_total_size is odd)
- Chunk identifier literal is
SHRD(riff.rs:11); length field counts chunk data only, excluding its 8-byte header and excluding the padding byte (riff.rs:147-157). - Appended strictly after all existing chunks without reordering (
riff.rs:142-145). -
$inject_size = 8 + ube_total_size + (ube_total_size & 1)$ (riff.rs:123-124);injectreturns$(host_len, inject_size, 4, old_riff_size)$ (riff.rs:160), indicating a 4-byte patch at offset 4.
riff.rs:126-133); writes "RIFF" + u32le(new_riff_size) + form_type (riff.rs:136-138). The RIFF size field represents "file length - 8"; hence post-injection file length is riff.rs:142-143).
RIFF headers remain unmodified; riff.rs:73-78, wav.rs:100-104, webp.rs:118-122).
| Feature | WAV | WebP |
|---|---|---|
| Form Type | WAVE |
WEBP |
| Chunk FourCC | SHRD |
SHRD (shared constant) |
riff_chunk Prerequisite |
Any valid RIFF/WAVE per §2 |
Extended Format: first chunk after 12B header MUST be VP8X (webp.rs:25-36, :53-68) |
| L1 Mandatory Chunks | fmt and data (wav.rs:77-85) |
Any one of VP8 , VP8L, or VP8X (webp.rs:96-104) |
| Capacity Note | Boundary mismatch notes "auto falls back to eof" (riff.rs:499-505) |
Notes Simple Format lacking VP8X (webp.rs:44-49) |
| Append Location | Physical EOF (after data / LIST) |
Physical EOF (after all top-level chunks) |
Let riff_chunk is eligible if and only if:
H == 8 + R
Chunk table spans H precisely
R + 8 + N + P <= 0xFFFF_FFFF <=> R + inject_size <= u32::MAX
The chunk size field can theoretically record
- Structural lower bound:
locaterequires chunk length$\ge 24$ (riff.rs:194);confine_locationrequires$ube_total_size \ge 112 + 24 = 136$ (engine.rs:191-207). Practical minimum envelopes aremin_ube_len(0) = 213andmin_ube_len(1) = 214(rust/src/structure/envelope.rs:123-140). - Engine payload limit:
$raw_size \le \text{clamp}(256 \times orig_host_size, 64\text{ MiB}, 1\text{ GiB})$ (engine.rs:1123,:1938-1943). - Overflow behavior:
autofalls back toeofwhenriff_can_chunkfails; explicitriff_chunkwith overflowing size returnsGeneral("RIFF 4GB container size overflow")(riff.rs:126-133), and boundary/table errors returnCorruptedDatasuggesting--strategy eof(riff.rs:93-121).
riff_locate executes in this order (riff.rs:163-228):
- File
$< 12\text{B}$ or first 4 bytes$\ne \text{"RIFF"} \to \text{Ok(None)}$ ; does NOT check form type or size fields at this step (riff.rs:167-176). - Scan top-level chunks forward from offset 12: read
[4CC][u32le size], advancing by$8 + size + (size & 1)$ (riff.rs:180-218). - On finding
SHRDwith$size \ge 24$ contained within EOF: read 24B trailer from$data_end - 24$ and unpack with expected trailer magic; if$trailer.ube_offset == data_offset$ and$trailer.ube_total_size == size$ , return(data_offset, size, "riff_chunk")(riff.rs:192-210). - Fallback to EOF trailer if not found in chunk scan: read 24B trailer from EOF, evaluating
locate_start(file_size)to return(start, ube_total_size, "eof")(riff.rs:221-225,envelope.rs:870-879). - Hints:
expected_header_magicis ignored; usesexpected_trailer_magiconly (adapters/mod.rs:218-225). Stealth trailer magic takes precedence over profile magic (engine.rs:145-166). - Containment check:
$ube_total_size \ge 136$ and$ube_offset + ube_total_size \le \text{file_size}$ (engine.rs:191-207), followed by coordinate cross-check with$offset_delta$ (engine.rs:2828-2902).riff_chunkdoes not permit relocation; coordinate desynchronization returnsCorruptedData(engine.rs:2268-2296).
WAV and WebP adapters use default strip: copies adapters/mod.rs:236-289).
-
riff_chunk: Skips the entireSHRDchunk (8B header + UBE + padding). Because offset 4 falls within$[0, inject_offset)$ , the modified size was initially copied, butpatch_offset = 4immediately restores$old_riff_size$ , reverting the RIFF size field to its original value; all other chunks are untouched. -
eof: Copies$[0, host_len)$ , with$patch_offset = 0$ . -
verify_restoredrecomputes restored file size and SHA-256 against$orig_host_size$ and$orig_host_sha256$ , returningRestoreMismatchon discrepancy (engine.rs:2298-2312).
LIST/INFO: Handled as standard top-level chunks based on outer length, without parsing sub-chunks (riff.rs:180-218,:406-446).fact: Neither checked nor required.data: Structural adapters neither parse nor modify sample data;SHRDappends pastdata.- WebP
VP8X: Checks only that FourCC at offset 12 isVP8X(riff.rs:36-47), without parsing canvas dimensions or flags. - Corrupted Chunks: If
riff_chunk_tablereturnsNoneorMissingFinalPad, writing is rejected;verify_structurereturns(false, details)(riff.rs:292-336). - Streaming WAVs (size = 0 or
0xFFFFFFFF):riff_chunkrejects,autoroutes toeof;verify_structurepermits EOF overlays on chunk boundaries (riff.rs:263-290). suspicious_structuresflags anySHRDchunk regardless of length (riff.rs:348-386).
- Writer details: Copy buffer sizes, streaming strategies, scan caching, and message phrasing are non-normative.
- Injection Sequence: Pre-write validation
$\to$ riff_injectwrites new RIFF header, copies chunks, appendsSHRD$\to$ engine backfills header atactual_ube_offsetand trailer at default trailer offset (engine.rs:1428-1441). RIFF does not overridefinalize. - Post-write verification:
locateMUST recover the written coordinates$(actual_ube_offset, ube_total_size)$ exactly; failures abort and clean up temporary files (engine.rs:1454-1472,:1601). - Regression tests:
tests/test_regression/review_20261025.rs:123-175validates$inject_offset = host_len$ ,$patch_offset = 4$ ,$inject_size = 8 + ube_total_size$ ;tests/test_lifecycle/matrix.rs:734-793covers Simple WebPauto -> eofand explicitriff_chunkrejection.