]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed new MIN_CBLOCK_SIZE
authorYann Collet <yann.collet.73@gmail.com>
Mon, 25 Jan 2016 16:26:01 +0000 (17:26 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 25 Jan 2016 16:26:01 +0000 (17:26 +0100)
lib/zstd_decompress.c
lib/zstd_internal.h

index 096d90ffe66f5dd804914be1f5818daebd04670a..a0f4d2d862d6acacba9d2863ccc0ab1a6db106a2 100644 (file)
@@ -351,14 +351,14 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
                 break;
             }
 
-            if (litSize > srcSize-11)   /* risk of reading beyond src buffer with wildcopy */
+            if (litSize+WILDCOPY_OVERLENGTH > srcSize)   /* risk reading beyond src buffer with wildcopy */
             {
                 if (litSize > srcSize-lhSize) return ERROR(corruption_detected);
                 memcpy(dctx->litBuffer, istart+lhSize, litSize);
                 dctx->litPtr = dctx->litBuffer;
                 dctx->litBufSize = BLOCKSIZE+8;
                 dctx->litSize = litSize;
-                return litSize+lhSize;
+                return lhSize+litSize;
             }
             /* direct reference into compressed stream */
             dctx->litPtr = istart+lhSize;
index a5d20409beec56face2bc8ad312cb2b284b0d8ff..3c3d78ce803b11ada6a972f6c335ee12e3189a16 100644 (file)
@@ -94,7 +94,9 @@ static const size_t ZSTD_frameHeaderSize_min = 5;
 #define MaxSeq MAX(MaxLL, MaxML)
 
 #define MIN_SEQUENCES_SIZE (2 /*seqNb*/ + 2 /*dumps*/ + 3 /*seqTables*/ + 1 /*bitStream*/)
-#define MIN_CBLOCK_SIZE (3 /*litCSize*/ + MIN_SEQUENCES_SIZE)
+#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + MIN_SEQUENCES_SIZE)
+
+#define WILDCOPY_OVERLENGTH 8
 
 typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
 
@@ -106,7 +108,7 @@ static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
 
 #define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
 
-/*! ZSTD_wildcopy : custom version of memcpy(), can copy up to 7-8 bytes too many */
+/*! ZSTD_wildcopy : custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */
 MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, size_t length)
 {
     const BYTE* ip = (const BYTE*)src;