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
//! Values and interfaces shared between the encoding side
//! and the decoding side.
// --- FRAMES ---
/// This magic number is included at the start of a single Zstandard frame
pub const MAGIC_NUM: u32 = 0xFD2F_B528;
/// Window size refers to the minimum amount of memory needed to decode any given frame.
///
/// The minimum window size is defined as 1 KB
pub const MIN_WINDOW_SIZE: u64 = 1024;
/// Window size refers to the minimum amount of memory needed to decode any given frame.
///
/// The maximum window size allowed by the spec is 3.75TB
pub const MAX_WINDOW_SIZE: u64 = + 7 * ;
// --- BLOCKS ---
/// While the spec limits block size to 128KB, the implementation uses
/// 128kibibytes
///
/// <https://github.com/facebook/zstd/blob/eca205fc7849a61ab287492931a04960ac58e031/doc/educational_decoder/zstd_decompress.c#L28-L29>
pub const MAX_BLOCK_SIZE: u32 = 128 * 1024;
/// Smallest accepted block-size target (upstream `ZSTD_TARGETCBLOCKSIZE_MIN`):
/// below this the per-block header overhead dominates any latency benefit.
/// Re-exported at the crate root as the single source of truth; the C ABI
/// parameter bounds import it from there.
pub const MIN_TARGET_BLOCK_SIZE: u32 = 1340;
/// Decoder window-size limit (128 MiB = `1 << 27`), matching upstream zstd's
/// default `ZSTD_d_windowLogMax` (`ZSTD_WINDOWLOG_LIMIT_DEFAULT = 27`). Frames
/// advertising a larger window are rejected to bound allocation on untrusted
/// input. The spec permits larger windows, but no standard zstd encoder emits
/// them by default, so matching the upstream limit keeps the drop-in contract:
/// every frame a stock zstd decoder accepts, we accept too — and crucially,
/// every frame OUR encoder emits (up to `window_log 27` at level 22) round-trips
/// through our own decoder. A non-power-of-two cap below `1 << 27` would reject
/// our own level-22 / streaming output (whose window header carries the full
/// 128 MiB). Decompression-bomb protection lives on the OUTPUT path, not here.
pub const MAXIMUM_ALLOWED_WINDOW_SIZE: u64 = 1 << 27;