CVE-2026-124851 in the Zstandard decoder, and why mzstd is not affected
CVE-2026-124851 lets crafted Zstandard data leak a 64 KiB internal buffer of the zstd 1.5.1–1.5.7 decoder into its output. How the leak works, what zstd 1.6.0 changes, and why mzstd's safe-Rust decoder and the ngx_mzstd module are not affected.
Summary
- CVE-2026-124851 is an information disclosure (CWE-226) in the decoder of the C Zstandard library, versions 1.5.1 through 1.5.7. Crafted compressed data makes the streaming decoder copy bytes of a 64 KiB internal buffer into its output: uninitialized heap memory, or literals of earlier decompressions on the same context.
- The fix is zstd 1.6.0, released on 23 November 2026. Anything that decodes untrusted Zstandard with the C library and lets the sender see the output has to upgrade.
- Two things combine. Literals are copied in 16-byte chunks, so stale bytes from the buffer land just past the current output. After the streaming ring buffer wraps, the decoder kept a stale view of it, and an offset past the window could point at those bytes. zstd 1.6.0 limits that view to the window and zeroes the bytes after the literals.
- We built a 3,099-byte frame that triggers the leak. zstd 1.5.7 returns 15 bytes of a previous frame’s literals, zstd 1.6.0 returns
Data corruption detected, and all 17 mzstd releases, 0.1.0 to 0.2.16, returnInvalidDataKind::Offset. - mzstd checks every offset against the frame’s window, drops the dictionary once the output passes the window as RFC 8878 requires, never wraps its history and holds no uninitialized memory. ngx_mzstd only compresses and is built without the decoder.
On 23 November 2026 Meta released zstd 1.6.0 and published CVE-2026-124851, an information disclosure in the decoder of the C Zstandard library. It was announced on oss-security the same night.
This post covers how the leak works, who needs to upgrade, and why mzstd, our Zstandard codec in Rust, and ngx_mzstd, our NGINX module, are not affected.
What the CVE says
| ID | CVE-2026-124851 |
| Product | Zstandard, decoder (lib/decompress/zstd_decompress_block.c) |
| Affected | 1.5.1 to 1.5.7 |
| Fixed | 1.6.0 (23 November 2026) |
| Weakness | CWE-226 Sensitive Information in Resource Not Removed Before Reuse |
| Severity | no CVSS score in the record as of 25 November 2026 |
| Fix | meta/zstd#5023 by Nick Terrell |
The record says that crafted data can “expose the contents of an internal buffer through decompressed output”. The buffer “is 64 KiB in the default configuration and may contain uninitialized memory or literals from earlier decompressions performed using the same decompression context”, and “an attacker who can submit compressed data and observe the resulting output can recover the buffer’s contents”.
That second condition matters. The attacker has to send a Zstandard body to a
vulnerable decoder and then see what came out. Examples include a service that
decompresses an upload and stores or echoes it, a proxy that decodes
Content-Encoding: zstd and forwards the result, or a pipeline that decompresses
messages from several tenants with one long-lived context. The leaked bytes are
whatever the buffer last held. That can be another user’s literals, or heap
memory that malloc returned without clearing.
Who has to upgrade
Anything that decodes untrusted Zstandard with the C library 1.5.1 to 1.5.7 and lets the sender see the output:
- the system
libzstdand everything linked against it; - language bindings that vendor the C sources, such as Rust’s
zstd-sys, and runtimes that bundle them; - statically linked binaries, which a distribution update of
libzstddoes not reach.
The changelog entry for the CVE reads “streaming decompression of malformed data could expose uninitialized memory”. The fix touches only the decoder. 1.6.0 fixes about twenty other bugs, several of them in the compressor and in the multithreaded and dictionary APIs, so upgrading is worthwhile even where this CVE does not apply.
How the leak works
The CVE record names no function. The fix, prevent stale literal leaks after output buffer wraps, does show the mechanism, and we reproduced it against 1.5.7. Two separate behaviours of the decoder combine.
Stale bytes past the output. Since zstd 1.5.1
(#2751, Reduce size of dctx by
reutilizing dst buffer), the decoder stages a block’s literals either in the
destination or in litExtraBuffer, a scratch array of ZSTD_LITBUFFEREXTRASIZE
bytes inside the decompression context. That is 64 KiB by default, and the
streaming decoder always uses it. The array is not cleared between blocks or
frames, and in a freshly allocated context it is uninitialized. Sequence
execution copies literals in 16-byte chunks for speed, so after a literal run it
has also written up to 32 bytes from past the literals’ end. Those bytes come from
the stale part of litExtraBuffer. Normally the match that follows overwrites
them.
A history view that outlives the window. In streaming mode the decoder
writes into a ring buffer of window + 2 × block + 64 bytes. When a block no
longer fits at the end, the decoder restarts at the beginning, and
ZSTD_checkContinuity turns everything decoded so far into an external
dictionary. A match offset is then checked only against the start of that
dictionary, not against the frame’s window. In 1.5.7 the external dictionary
kept its full length while the new output grew over the same memory. So an
offset could reach “history” that was really the ring buffer at or just past the
current write position. That memory had just received the stale bytes from the
literal copy, and the match copied them into the output.
zstd 1.6.0 fixes both sides:
- once a full window has been decoded,
ZSTD_checkContinuitytrims the external dictionary towindowSizeminus the current prefix, so offsets can no longer reach expired memory; - a new
ZSTD_zeroLiteralsBufferPaddingzeroes the 32 bytes after every block’s literals, including both halves of a split literal buffer, so the chunked copy only ever reads zeros past the end.
Reproducing it
To check our understanding, and mzstd’s behaviour, against real code rather than reasoning, we wrote a 3,099-byte frame by hand:
- A frame header with a 1 KiB window and no content size, so the streaming decoder uses a 3,136-byte ring buffer.
- Three raw blocks of 1 KiB each. After the third, the next block does not fit and the ring buffer wraps.
- One compressed block holding a single RLE literal
Aand one sequence: literal length 1, offset 3,072, match length 15. The offset is three times the window.
Before it, the same context decompressed a 3,000-byte “secret”: random text over
the alphabet SECRETsecret0123. It was decoded through ZSTD_decompressStream,
so its literals passed through litExtraBuffer. A second frame, identical except
for an offset of 1,024, served as the control.
| Decoder | Crafted frame (offset 3,072) | Control (offset 1,024) |
|---|---|---|
| zstd 1.5.7 | decodes; last block is A2EtttCtEs1300Ee |
A and 15 dots |
| zstd 1.6.0 | Data corruption detected |
A and 15 dots |
| mzstd, all releases 0.1.0 to 0.2.16 | InvalidDataKind::Offset |
A and 15 dots |
The 15 bytes after the A in the 1.5.7 output are exactly bytes 1 to 15 of the
secret. When the secret was decoded through the one-shot path instead, its
literals never passed through litExtraBuffer, and 1.5.7 leaked 15 unprintable
bytes of uninitialized heap. A longer literal run moves the over-read further into
litExtraBuffer, which is how the whole buffer can be recovered, as the advisory
says.
On the mzstd side, 0.2.16 got the crafted frame through a streaming session after
the secret, through one session holding both frames, through decompress and
through decompress_to_slice. All 17 releases on crates.io, 0.1.0 to 0.2.16,
also got it through decompress. Every one rejects the frame with
InvalidDataKind::Offset and decodes the control the same way as zstd.
Why mzstd is not affected
mzstd does not link the C library. Its decoder is a separate implementation of RFC 8878 in Rust, and the crate is built with
#![cfg_attr(not(test), forbid(unsafe_code))]
That alone rules out half of the CVE. Every buffer in the decoder is a Vec<u8>
that is zero-filled when it grows, so there is no uninitialized memory for a
stream to expose. The other half, stale data from earlier work, is a logic
property that safe Rust does not guarantee. Three design choices are what
prevent it.
Offsets are checked against the window. Before a match is copied, mzstd
compares its offset with the frame’s Window_Size, not with the start of
whatever buffer happens to hold history:
let reach = if dictionary.is_empty() {
lit_end.min(window)
} else {
lit_end + dictionary.len()
};
if offset > reach {
return Err(InvalidDataKind::Offset.into());
}
A dictionary is passed in only while the frame’s output is still within its
first window. Once the output passes the window, the dictionary is dropped and
the window limits every offset again. That is the rule RFC 8878 states: “After
the total output has surpassed Window_Size however, this is no longer allowed
and the dictionary is no longer accessible.” zstd 1.6.0 now applies the same rule
to its own history after a wrap. The mzstd 0.2.16 changelog notes that the
decoder needed no change for 1.6.0 for this reason.
History never wraps, and nothing aliases it. The streaming decoder keeps its
output in one contiguous buffer that doubles as the window. Before a block,
once everything has been delivered and the buffer has grown a window past what
it needs, it moves the last window to the front with copy_within and continues
after it. No region is ever both “old history” and “where the next block goes”,
which is the overlap the C decoder lost track of. A dictionary is a separate
borrowed slice. It is never part of the output buffer.
Stale literals never get into the output. mzstd also reuses its literal
buffer between blocks and frames, and it also copies literals in 32-byte chunks,
so the bytes just past the current output can briefly hold literals of an
earlier block. What it does not allow is a match that reads them. A match can
only reach bytes before the end of the current literals (offset ≤ lit_end), or
the dictionary, and everything before that point is real output. The stale bytes
are always ahead of the write position, and the next copy overwrites them.
Sequences near the end of the buffer take an exact path with no chunked copy.
We tested that last property too. After decoding a 60 KB frame with Huffman-coded
literals, we decoded small frames into a caller buffer prefilled with 0xAA.
Every byte past the returned length was still 0xAA. The decompress fuzz
target asserts the same for every input: decoding into an uninitialized
destination leaves everything past the reported size untouched.
Where mzstd is stricter than zstd
The C decoder, 1.6.0 included, does not compare offsets with the window inside its own buffer. In an earlier run, the context had first decoded a 60 KB frame and kept its larger ring buffer. That buffer did not wrap, and zstd 1.6.0 decoded the crafted frame without an error, reading data 3 KiB back in a frame that declared a 1 KiB window. The data was the frame’s own output, so nothing leaked. Still, whether 1.6.0 accepts a frame depends on what the context decoded before.
mzstd rejects any offset beyond Window_Size, apart from dictionary references
within the first window, whatever its buffers hold. Every frame zstd’s encoder
produces respects the window, so both decoders produce the same output for real
data. They disagree only on malformed frames like this one, and mzstd’s answer
does not depend on earlier frames.
Why ngx_mzstd is not affected
ngx_mzstd is an NGINX filter that compresses responses on the fly. It never
decodes Zstandard, and its build reflects that. It depends on mzstd with
default-features = false and only the std and compression features, so
mzstd’s decoder is not compiled into the module. The decoder is enabled only in
its tests, which decode what the filter produced.
NGINX itself does not decode Zstandard either. If a proxy in front of or behind
it does, for example to inspect or rewrite zstd bodies, that proxy needs
zstd 1.6.0.
The C ABI in mzstd-ffi wraps mzstd’s own decoder. The vendored C zstd in the
mzstd repository is a dev-dependency that the tests use as the reference; it is
never built into a published crate.
What to do
- Find every copy of the C Zstandard decoder you run: system
libzstd, bundled copies in runtimes and language packages, statically linked binaries. - Upgrade to zstd 1.6.0, or to a release of the runtime or binding that bundles it.
- If you use mzstd, nothing is needed for this CVE. 0.2.16 keeps encoding byte-identical to zstd 1.6.0; its decoder is the same as in 0.2.15.
- ngx_mzstd needs no change.
Security reports for mzstd and the other M-Compressors projects go through the private process in each repository’s SECURITY.md.
Questions
What is CVE-2026-124851?
An information disclosure in the Zstandard decoder of zstd 1.5.1 through 1.5.7. Crafted compressed data can make the decoder copy the contents of a 64 KiB internal buffer, which may hold uninitialized memory or literals from earlier decompressions on the same context, into the decompressed output. It is fixed in zstd 1.6.0.
Which zstd versions are affected by CVE-2026-124851?
1.5.1 through 1.5.7. Versions before 1.5.1 do not have the internal literal buffer the leak reads from. Upgrade to 1.6.0.
Is the zstd compressor affected?
No. The fix changes only lib/decompress/zstd_decompress_block.c, and the leak needs the decoder’s streaming output buffer. zstd 1.6.0 fixes a number of other bugs, including some in the compressor, so it is worth upgrading anyway.
Is mzstd affected by CVE-2026-124851?
No. mzstd does not use the C library. Its decoder is written in safe Rust and checks every match offset against the frame’s window, so the crafted frame fails with InvalidDataKind::Offset. Its buffers are always initialized, so there is no uninitialized memory to leak. All 17 releases, 0.1.0 to 0.2.16, reject the frame.
Is ngx_mzstd affected by CVE-2026-124851?
No. ngx_mzstd compresses responses and never decodes Zstandard. It depends on mzstd with only the std and compression features, so no decoder is compiled into the module.
Do I need to upgrade mzstd?
Not for this CVE. mzstd 0.2.16 moves the reference to zstd 1.6.0 so that single-threaded encoding stays byte-identical to it, but its decoder did not change.
Cite this post
Mikhail Panfilov. “CVE-2026-124851 in the Zstandard decoder, and why mzstd is not affected.” M-Compressors, 25 November 2026. https://m-compressors.github.io/2026/zstd-cve-2026-124851-mzstd/