xz_dec_init(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… xz_dec_init(9) β€” like, the Kernel API Manual, bestie ✨

okay so real talk, this page is from the Kernel API Manual and it's literally all about xz_dec_init(9) πŸŽ€ β€” the little function that gets your XZ decoder state all set up and ready to slay. Think of it as getting your decoder dressed and out the door πŸ’–


🌸 NAME 🌸

xz_dec_init β€” allocate and initialize a XZ decoder state πŸ¦‹


✨ SYNOPSIS ✨

struct xz_dec * xz_dec_init (enum xz_mode mode , uint32_t dict_max );

like, that's the whole signature. no cap. πŸ‘‘


🫢 ARGUMENTS 🫢

  • mode β€” the operation mode 🎚️ (yes there are modes, keep reading bestie)
  • dict_max β€” the maximum size of the LZMA2 dictionary (aka the history buffer) for multi-call decoding πŸ’Ύ
⚠️ heads up: dict_max is ignored in single-call mode (mode == XZ_SINGLE). literally doesn't even look at it πŸ™ˆ

okay so about the dictionary size β€” an LZMA2 dictionary is always either 2^n bytes or 2^n + 2^(n-1) bytes (that second flavor is less common in practice, ngl), so any other value for dict_max is just... not it. doesn't make sense, don't do it πŸ’€

in the kernel, 64 KiB, 128 KiB, 256 KiB, 512 KiB, and 1 MiB are probably the only reasonable values πŸ’… β€” with one exception: for kernel and initramfs images, a bigger dictionary can be totally fine and actually useful, so go off πŸ‘‘


πŸ”₯ DESCRIPTION πŸ”₯

okay so this is the part where it gets good. there are three whole vibes here and you need to know which one you're in:

Single-call mode (XZ_SINGLE) ⭐

xz_dec_run decodes the whole stream at once. one and done, periodt. the caller must provide enough output space, otherwise the decoding will straight-up fail 😭. here's the cute part: the output space is used as the dictionary buffer, which is exactly why there's no need to allocate the dictionary as part of the decoder's internal state. it's giving efficiency πŸ’…

and because the output buffer is the workspace, streams encoded using a big dictionary are not a problem in single-call mode πŸ¦‹ it's enough that the output buffer is big enough to hold the actual uncompressed data β€” it can totally be smaller than the dictionary size stored in the stream headers. iconic, frankly.

Multi-call mode with preallocated dictionary (XZ_PREALLOC) πŸŽ€

here, dict_max bytes of memory is preallocated for the LZMA2 dictionary. this way there's no risk that xz_dec_run could run out of memory, since xz_dec_run will never allocate any memory πŸ”’

but β€” and this is the catch, bestie β€” if the preallocated dictionary is too small for decoding the given input stream, xz_dec_run will return XZ_MEMLIMIT_ERROR πŸ’€. so it's super important to know what kind of data will be decoded, or you'll be out here allocating an excessive amount of memory for the dictionary. no wasteful queen behavior πŸ™ˆ

Multi-call mode with dynamically allocated dictionary (XZ_DYNALLOC) 🌈

dict_max specifies the maximum allowed dictionary size that xz_dec_run may allocate once it has parsed the dictionary size from the stream headers πŸ“œ. this way excessive allocations can be avoided while still limiting the maximum memory usage to a sane value β€” which prevents running the system out of memory when decompressing streams from untrusted sources πŸ”₯. like, security and hygiene, we love to see it.

the return value, bestie 🫢

on success, xz_dec_init returns a pointer to struct xz_dec, which is ready to be used with xz_dec_run. and if memory allocation fails? it returns NULL. that's it. that's the whole mood 😭


πŸ’œ SEE ALSO πŸ’œ

Kernel file ./include/linux/xz.h


✨ ok that's the whole page, go decode something iconic ✨

this lil manual page lives in ./include/linux, dated October 2026, and it's filed under xz_dec_init(9) β€” catch you in the next one bestie πŸ’–πŸŽ€πŸ¦‹πŸ‘‘

πŸ“¦ where this page comes from