On Tue Nov 24, 2026 at 11:28 AM CET, Stuart Henderson wrote:
> On 2026/11/24 07:12, Bjorn Ketelaars wrote:
>> CVE-2026-124851, where malformed input during streaming decompression
>> may expose uninitialized memory or data from previous decompressions,
>> affects the zstd version in -stable. Updating to 1.6.0 does not seem
>> suitable for -stable due to the major shlib bump.
>>
>> The actual upstream fix is relatively small:
>> https://github.com/meta/zstd/pull/5023
>>
>> Proposal is to backport this to -stable. 'make test' passes all tests on
>> amd64.
>>
>> OK?
>>
>>
>> Index: Makefile
>> ===================================================================
>> RCS file: /cvs/ports/archivers/zstd/Makefile,v
>> diff -u -p -r1.49 Makefile
>> --- Makefile 17 May 2025 17:14:13 -0000 1.49
>> +++ Makefile 24 Nov 2026 06:01:55 -0000
>> @@ -1,7 +1,7 @@
>> COMMENT = zstandard fast real-time compression algorithm
>>
>> V = 1.5.7
>> -REVISION = 0
>> +REVISION = 1
>> DISTNAME = zstd-${V}
>>
>> SHARED_LIBS = zstd 7.0 # 1.5.7
>> @@ -18,6 +18,10 @@ PERMIT_PACKAGE = Yes
>> WANTLIB = c lz4 lzma pthread z
>>
>> SITES =
>> https://github.com/facebook/zstd/releases/download/v${V}/
>> +
>> +SITES.p = https://github.com/meta/zstd/commit/
>> +PATCHFILES.p = decompress-stale-literal-wrap-{}0c9d297.patch
>> +PATCH_DIST_STRIP = -p1
>
> These github patch files are particularly unstable. Please use port
> patches or mirror.
New diff below, which uses a port patch.
Index: Makefile
===================================================================
RCS file: /cvs/ports/archivers/zstd/Makefile,v
diff -u -p -r1.49 Makefile
--- Makefile 17 May 2025 17:14:13 -0000 1.49
+++ Makefile 24 Nov 2026 17:59:29 -0000
@@ -1,7 +1,7 @@
COMMENT = zstandard fast real-time compression algorithm
V = 1.5.7
-REVISION = 0
+REVISION = 1
DISTNAME = zstd-${V}
SHARED_LIBS = zstd 7.0 # 1.5.7
Index: patches/patch-lib_decompress_zstd_decompress_block_c
===================================================================
RCS file: patches/patch-lib_decompress_zstd_decompress_block_c
diff -N patches/patch-lib_decompress_zstd_decompress_block_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-lib_decompress_zstd_decompress_block_c 24 Nov 2026
17:59:29 -0000
@@ -0,0 +1,90 @@
+From 0c9d297531a9f15a717ff24604afc0843b3b1427 Mon Sep 17 00:00:00 2001
+From: Nick Terrell <[email protected]>
+Date: Fri, 6 Nov 2026 08:53:26 -0800
+Subject: [PATCH] decompress: prevent stale literal leaks after output buffer
+ wraps
+
+After the streaming output buffer wraps, the external dictionary and
+current prefix must share the frame history window. Retaining expired
+history can allow malformed offsets to expose uninitialized bytes or
+literals from earlier decompressions on the same context.
+
+Once a full window has been decoded, limit external history to the
+portion not occupied by the current prefix. Apply this bound before
+subsequent blocks even when output remains contiguous. Also zero the
+wildcopy padding after decoder-owned literals, including both parts of a
+split literal buffer, so permitted over-reads only see initialized bytes.
+
+Index: lib/decompress/zstd_decompress_block.c
+--- lib/decompress/zstd_decompress_block.c.orig
++++ lib/decompress/zstd_decompress_block.c
+@@ -123,6 +123,25 @@ static void ZSTD_allocateLiteralsBuffer(ZSTD_DCtx* dct
+ }
+ }
+
++/**
++ * Zeros the bytes directly after the decompressed literals so that over-reads
++ * only read zeros, rather than potentially uninitialized memory, or bytes
from
++ * prior decompressions.
++ */
++static void ZSTD_zeroLiteralsBufferPadding(ZSTD_DCtx* dctx, size_t litSize)
++{
++ if (dctx->litBufferLocation == ZSTD_split) {
++ BYTE* const litBufferEnd = dctx->litBuffer + litSize -
ZSTD_LITBUFFEREXTRASIZE;
++ assert(litBufferEnd == dctx->litBufferEnd);
++ ZSTD_memset(litBufferEnd, 0, WILDCOPY_OVERLENGTH);
++ ZSTD_memset(dctx->litExtraBuffer + ZSTD_LITBUFFEREXTRASIZE, 0,
WILDCOPY_OVERLENGTH);
++ } else {
++ BYTE* const litBufferEnd = dctx->litBuffer + litSize;
++ assert(litBufferEnd == dctx->litBufferEnd);
++ ZSTD_memset(litBufferEnd, 0, WILDCOPY_OVERLENGTH);
++ }
++}
++
+ /*! ZSTD_decodeLiteralsBlock() :
+ * Where it is possible to do so without being stomped by the output during
decompression, the literals block will be stored
+ * in the dstBuffer. If there is room to do so, it will be stored in full in
the excess dst space after where the current
+@@ -240,6 +259,7 @@ static size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx
+
+ RETURN_ERROR_IF(HUF_isError(hufSuccess), corruption_detected,
"");
+
++ ZSTD_zeroLiteralsBufferPadding(dctx, litSize);
+ dctx->litPtr = dctx->litBuffer;
+ dctx->litSize = litSize;
+ dctx->litEntropy = 1;
+@@ -283,6 +303,7 @@ static size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx
+ {
+ ZSTD_memcpy(dctx->litBuffer, istart + lhSize,
litSize);
+ }
++ ZSTD_zeroLiteralsBufferPadding(dctx, litSize);
+ dctx->litPtr = dctx->litBuffer;
+ dctx->litSize = litSize;
+ return lhSize+litSize;
+@@ -329,6 +350,7 @@ static size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx
+ {
+ ZSTD_memset(dctx->litBuffer, istart[lhSize], litSize);
+ }
++ ZSTD_zeroLiteralsBufferPadding(dctx, litSize);
+ dctx->litPtr = dctx->litBuffer;
+ dctx->litSize = litSize;
+ return lhSize+1;
+@@ -2182,6 +2204,19 @@ void ZSTD_checkContinuity(ZSTD_DCtx* dctx, const void*
+ dctx->virtualStart = (const char*)dst - ((const
char*)(dctx->previousDstEnd) - (const char*)(dctx->prefixStart));
+ dctx->prefixStart = dst;
+ dctx->previousDstEnd = dst;
++ }
++ /* The external dictionary and current prefix share the frame window.
++ * As the prefix grows after a wrap, retaining a full external window
++ * could let corrupt offsets alias the destination and expose stale
literals.
++ * decodedSize > 0 ensures the frame header has initialized windowSize.
++ * Only kicks in after decoding windowSize bytes because the entire
dictionary is
++ * valid as long as a single byte of the dictionary is in the window.
++ */
++ if (dstSize > 0 && dctx->isFrameDecompression && dctx->decodedSize > 0 &&
dctx->decodedSize >= dctx->fParams.windowSize) {
++ size_t const prefixSize = (size_t)((const char*)dctx->previousDstEnd
- (const char*)dctx->prefixStart);
++ size_t const extDictSize = (size_t)((const char*)dctx->prefixStart -
(const char*)dctx->virtualStart);
++ U64 const maxExtDictSize = prefixSize < dctx->fParams.windowSize ?
dctx->fParams.windowSize - prefixSize : 0;
++ dctx->virtualStart = (const char*)dctx->prefixStart -
(size_t)MIN((U64)extDictSize, maxExtDictSize);
+ }
+ }
+