Expand description
CAP-file parser — PDD §5.4a (Java Card VM Spec v3.1 Ch. 6). Pure; top fuzz target (§10.5 #1: parses an attacker-influenceable ZIP).
A .cap is a ZIP. The parser locates the components and presents the Load
File Data Block in GPCS §C.2 order: Header | Directory | Import | Applet |
Class | Method | StaticField | Export | ConstantPool | RefLocation |
Descriptor | [Debug excluded].
no_std, streaming. The full LFDB is never materialized: CapFile borrows
the input ZIP, and the LFDB is produced one LOAD_BLOCK_DATA-sized chunk
at a time via LoadFileDataBlock::next_block. The caller feeds each chunk
to both the LFDB hasher and the LOAD command (§5.4a) incrementally.
Compression: STORED + DEFLATE, alloc-free. STORED entries are read
directly from the borrowed input. DEFLATE entries are inflated with
miniz_oxide (default-features = false, no alloc) into a caller-lent
32 KiB window (InflateCtx); the window is used as a wrapping LZ77
dictionary ring (RFC 1951’s 32 KiB max match distance), so a component of
any size streams through it without heap or a full-output buffer, and host
and embedded share one code path. The standard JavaCard converter emits
DEFLATE JARs, so no host-side repack is required.
Structs§
- Applet
Entry - One applet class entry from
Applet.cap. - CapComponents
- Extracted CAP components relevant to loading/installing.
- CapFile
- Parsed CAP file. Borrows the input ZIP bytes for the lifetime
'a; the Load File Data Block is produced on demand (never owned). - Inflate
Ctx - Caller-owned DEFLATE working set for compressed components: the 32 KiB
wrapping window (
INFLATE_WINDOW) used as the LZ77 dictionary ring, plusminiz_oxide’s decompressor state. Allocate once (it is large — the window plus a multi-KB Huffman-table state struct; place it in astaticor on a generous stack) and lend it toLoadFileDataBlock::next_block. It is untouched while a STORED component is being read. - Load
File Data Block - Streaming Load File Data Block. Stateful pull reader: each call to
Self::next_blockwrites the next chunk into the caller’s buffer, so the whole block never resides in RAM at once.
Enums§
- CapError
- CAP parse failure.
Functions§
- parse
- Parse a
.cap(ZIP) byte buffer. Borrowscap_zipfor the returnedCapFile’s lifetime. STORED and DEFLATE entries are both accepted.