]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix issue 5921623844651008 3900/head
authorYann Collet <cyan@fb.com>
Tue, 6 Feb 2024 20:15:54 +0000 (12:15 -0800)
committerYann Collet <cyan@fb.com>
Tue, 6 Feb 2024 21:01:14 +0000 (13:01 -0800)
ossfuzz managed to create a scenario which triggers an `assert`.
This fixes it, by giving +1 more space for the backward search pass.

lib/compress/zstd_compress_internal.h
lib/compress/zstd_opt.c

index 087ea49dcf8810cf20b52f8edeb5a4b52f1121ef..e41d7b78ec6aaa5bd237667f4a9efcc81bf8a97c 100644 (file)
@@ -168,7 +168,7 @@ typedef struct {
 
 typedef enum { zop_dynamic=0, zop_predef } ZSTD_OptPrice_e;
 
-#define ZSTD_OPT_SIZE (ZSTD_OPT_NUM+2)
+#define ZSTD_OPT_SIZE (ZSTD_OPT_NUM+3)
 typedef struct {
     /* All tables are allocated inside cctx->workspace by ZSTD_resetCCtx_internal() */
     unsigned* litFreq;           /* table of literals statistics, of size 256 */
index 8e1be1cec184f63bc0d44abea80c3edc928e8219..0449204ddd8f83e75760ff450bb6d718b1e0819b 100644 (file)
@@ -1196,7 +1196,7 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms,
         /* check further positions */
         for (cur = 1; cur <= last_pos; cur++) {
             const BYTE* const inr = ip + cur;
-            assert(cur < ZSTD_OPT_NUM);
+            assert(cur <= ZSTD_OPT_NUM);
             DEBUGLOG(7, "cPos:%zi==rPos:%u", inr-istart, cur);
 
             /* Fix current position with one literal if cheaper */