inflateSetDictionary
Install or amend the bytes available for backward matches.
Full chapter and shared rules ↗ecafc184cdf44b7f · Source at the matching commit ↗Read the function’s preconditions and results first. Expand the shared rules below for buffer and ownership requirements used throughout this API group.
int ZEXPORT inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength);
Install or amend the bytes available for backward matches.
Domain Restricted domain: live zlib streams waiting after Z_NEED_DICT, or
live raw streams at any call boundary.
Effects Mutates history and may allocate its window.
Pre dictionary is non-NULL and describes dictLength readable bytes, even
when the length is zero. For correct output it matches the compressor's dictionary.
Post Returns Z_OK after retaining the last window-sized suffix of old
history followed by the new dictionary. The whole supplied dictionary is checked
against the zlib identifier. Caller bytes are copied, not retained or freed.
Errors A wrong zlib identifier returns Z_DATA_ERROR unchanged; another
dictionary can be tried. NULL dictionary, failed stream check or wrapped stream
not awaiting a dictionary returns Z_STREAM_ERROR. Allocation failure returns
Z_MEM_ERROR and leaves the stream in the memory-error mode, still endable.
Edges Gzip has no preset-dictionary path. Raw mode has no identifier check; a wrong dictionary can produce wrong output or a later error. Zero-length raw dictionaries are accepted. No input/output pointers or totals are advanced.
Shared conditions and scope
API manual · Shared stream rules · Stream compression
Use an inflate stream to decode input in pieces while controlling output space. Select zlib,
gzip or raw DEFLATE at initialization, then continue with more input or room until completion,
a dictionary request or an error. End releases the decoder after any of those outcomes.
For whole-buffer zlib decoding, see uncompress.
| Task | Entries |
|---|---|
| Start or reuse | Init, configured init, reset, new configuration, keep history |
| Decode or provide metadata | Inflate, set dictionary, read history, gzip header |
| Recover or inspect | Sync search, sync point, mark, table use |
| Adjust or branch | Prime bits, validation, distance option, copy |
| Release storage | End |
The focused contracts follow the pinned inflate.c and zlib.h in the default LP64 Linux
build, with gzip enabled and without optional invalid-distance or strict-distance modes.
Source readings are to confirm by proof. The broader registered public goals
retain their domains. See contract conventions for terminology and
progress for proof status and remaining work.
Common conditions
All contracts below have a Restricted domain. A C pointer type alone does not supply the storage, lifetime or call history required here.
- A live stream was successfully initialised or copied, has not been ended, retains its library-owned state, and is used without concurrent calls. Use the default allocator and free function. Init takes a writable, non-live stream with allocator fields set to NULL or the default functions.
- A readable or writable range has the stated capacity for the whole call. Caller ranges are separate from the stream and its owned storage. Input and output ranges do not overlap. Dictionary destinations, the registered header record and its destination buffers are separate from each other and from the stream. Registered header storage is also separate from input/output ranges on calls using it. These are explicit focused-domain restrictions.
- The caller owns its stream object and buffers. The library owns the state and optional window. A call changes only its stream, owned storage, stated output ranges and any registered header destination. It never frees caller buffers.
- A rejected stream check returns
Z_STREAM_ERRORwithout changes, unless a query or copy contract says otherwise. This covers NULL and safely readable records rejected by the check; it does not cover dangling or arbitrary pointers. The check requires allocators, state, the state's back-pointer and a valid mode. - Counters use the C unsigned widths and wrap. No contract assumes allocation succeeds. End remains available after decoding, dictionary or allocation errors.
flowchart LR
I["Init"] --> F["inflate"]
F -->|"Z_NEED_DICT"| D["SetDictionary"] --> F
F -->|"more room or input"| F
F -->|"end or abandon"| E["End"]
F -->|"data error"| R["Reset or Sync"] --> F
Formal contract
ZlibF.Spec.Public.Goal.inflateSetDictionary
Proof status: Registered proof · Evidence and remaining work
/-- `int inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)`.
Raw streams append to their window. Wrapped streams require DICT mode and the exact Adler id. -/
def Goal.inflateSetDictionary : Prop :=
∀ h r i z s source n xs old,
Zlib.Inflate.Spec.Good h r i z s → z.zalloc = .fn "zcalloc" →
InflateDictionary h s old → (source ≠ .null → Bytes h source n.toNat xs) →
Separate source n.toNat s.window (2 ^ s.wbits.toNat) →
((s.wrap = 0 ∨ s.mode = DICT) → 8 ≤ s.wbits.toNat) →
∃ rc after, C.run (Zlib.Inflate.inflateSetDictionary (some r) source n) h = .ok (rc, after) ∧
(source = .null ∨ (s.wrap ≠ 0 ∧ s.mode ≠ DICT) → rc = Z_STREAM_ERROR ∧ after = h) ∧
(source ≠ .null → (s.wrap = 0 ∨ s.mode = DICT) →
if s.mode = DICT ∧ s.check ≠ (ZlibF.Spec.adler32 xs).toUInt64 then rc = Z_DATA_ERROR ∧ after = h
else (rc = Z_MEM_ERROR ∧ AllocationFailed h after ∧
∃ s', Zlib.Inflate.Spec.Good after r i z s' ∧ s'.mode = MEM) ∨
(rc = Z_OK ∧ ∃ s', Zlib.Inflate.Spec.Good after r i z s' ∧
s'.havedict = 1 ∧ s'.mode = s.mode ∧
InflateDictionary after s' ((old ++ xs).drop ((old ++ xs).length - 2 ^ s.wbits.toNat)))) ∧
Frame h after (fun b => StreamRoot r b ∨ InflateOwned i s b) ∧
(∃ s', h.istates i = some s ∧ after.istates i = some s' ∧
LiveChange h after (fun b => InflateOwned i s' b ∧ ¬ h.live b) (fun _ => False))Related definitions and source ↗