From ed9e5daec21f827c76ca9d82febe6857409548b8 Mon Sep 17 00:00:00 2001 From: evilgensec Date: Thu, 6 Aug 2026 09:03:14 +0545 Subject: [PATCH] [benchmark] advance the decodeOnly result cursor by the decompressed size In BMK_benchMemAdvancedNoAlloc the result buffer is allocated at the total decompressed size of all inputs, and resSizes[chunkID] is set per chunk to ZSTD_findDecompressedSize() in decodeOnly mode. The write cursor, however, advanced by chunkSize, which in decodeOnly mode is the compressed size of the file rather than its decompressed size. Chunk i therefore received a destination pointer at the sum of the preceding compressed sizes inside a buffer sized by the sum of the decompressed sizes. Whenever an input compresses to more bytes than it decompresses to, the cursor runs ahead of the allocation and later chunks are handed a dst that lies outside it. A skippable frame is the simplest case, since it costs compressed bytes and contributes nothing to the decompressed size. Advance by resSizes[chunkID] instead. It is assigned three lines earlier, so it is already available. In non-decodeOnly mode resSizes[chunkID] is exactly chunkSize, which makes this a no-op there. In decodeOnly mode it makes the sum of the per-chunk sizes equal the decodedSize passed to malloc, because line 514 issues the same ZSTD_findDecompressedSize call over the same ranges as the validation loop above. --- programs/benchzstd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/benchzstd.c b/programs/benchzstd.c index f55c8697504..4bc300b81b6 100644 --- a/programs/benchzstd.c +++ b/programs/benchzstd.c @@ -517,7 +517,7 @@ static BMK_benchOutcome_t BMK_benchMemAdvancedNoAlloc( : chunkSize; srcPtr += chunkSize; cPtr += cCapacities[chunkID]; - resPtr += chunkSize; + resPtr += resSizes[chunkID]; remaining -= chunkSize; if (adv->mode == BMK_decodeOnly) { cSizes[chunkID] = chunkSize;