Skip to main content

Module codec

Module codec 

Source
Expand description

Codec inner loops as unchecked pointer code (owned by the simoom-compress work). Codec inner loops as unchecked pointer code (owned by the simoom-compress work).

simoom-compress keeps a safe implementation of each loop as the reference; these are the fast versions it calls when fast says so. Every loop establishes its bounds before it starts (sizes, slack after the buffers) and checks per step exactly what the untrusted input controls (lengths, offsets), so no input can make it read or write outside the slices it was given. The tests and fuzzers of simoom-compress compare the two implementations on every input.

Structs§

FastIn
The inputs of zstd_fast.
FseEnc
An FSE encoding table: next states (log at most 9) and per-symbol transforms (symbols below 64).
Huf4
The state of zstd’s four-stream Huffman fast loop (HUF_decompress4X1 “fast”): per stream a left-aligned 64-bit container with a marker bit below the unread bits, and its position in the input.
Match
One match of an LZ77 parse: lit literals, then len bytes from dist back.
SeqCode
One zstd sequence ready to code: the three codes, the extra-bit counts of the lengths, and the extra values (the offset value’s extra bits are of_code of them).
SeqEntry
A zstd sequence decoding table entry: the code’s base value and extra bits, and the next state’s base and bits (zstd’s ZSTD_seqSymbol).
Sequences
The inputs of zstd_sequences.
SymTT
An FSE encoding table entry (zstd’s FSE_symbolCompressionTransform).

Enums§

SeqError
Why zstd_sequences stopped.

Constants§

WILD
Bytes of slack the zstd loops need after the literals and after the output limit.

Functions§

fast
Whether callers should use these loops (false after set_safe_only on this thread).
huf4
Runs the four-stream fast loop as far as it can go without reading before a stream’s start or writing past stream 3’s output (five symbols per stream per round); returns the updated positions, containers and symbol count. Same results as simoom-compress’s safe loop.
set_safe_only
Makes fast return false on this thread (true) or true again (false): for tests and fuzzing that compare the safe reference implementations with these loops.
zstd_fast
zstd’s fast (level 1: one table) and double-fast (levels 2-3: long_log > 0) match finders over buf[from..to], appending matches to out; returns the literals left after the last match and the repeat offsets. Same results as simoom-compress’s safe Fast.
zstd_seq_stream
Writes the sequences bitstream of a zstd block (RFC 8878 section 4.1.2: last sequence first, the three FSE states interleaved, extras, end marker) for codes (at least one) with tables [literal lengths, offsets, match lengths], appending it to out. Same bytes as simoom-compress’s safe writer.
zstd_sequences
Decodes and executes a zstd block’s sequences (RFC 8878 section 3.1.1.3.2 and 3.1.1.4). Returns the end of the output written (the remaining literals after the last sequence are left to the caller) and the repeat offsets; the bytes after the end up to the slack are garbage. Same results as simoom-compress’s safe execute.