]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
make ZSTD_DECOMPRESSBOUND() compatible with input size 0 3373/head
authorYann Collet <cyan@fb.com>
Fri, 16 Dec 2022 23:58:25 +0000 (15:58 -0800)
committerYann Collet <cyan@fb.com>
Sat, 17 Dec 2022 00:05:39 +0000 (16:05 -0800)
for environments with stringent compilation warnings.

lib/zstd.h
tests/fuzzer.c

index 065a1d652a45e5340f84ce8aa584af514f4cc9de..09a200af20f6b08e77d972514ee0648b7cb756cc 100644 (file)
@@ -228,7 +228,7 @@ ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
  * Will produce constant value 0 if srcSize too large.
  */
 #define ZSTD_MAX_INPUT_SIZE ((sizeof(size_t)==8) ? 0xFF00FF00FF00FF00LLU : 0xFF00FF00U)
-#define ZSTD_COMPRESSBOUND(srcSize)   (((size_t)(srcSize) > ZSTD_MAX_INPUT_SIZE) ? 0 : (srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0))  /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */
+#define ZSTD_COMPRESSBOUND(srcSize)   (((size_t)(srcSize) >= ZSTD_MAX_INPUT_SIZE) ? 0 : (srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0))  /* this formula ensures that bound(A) + bound(B) <= bound(A+B) as long as A and B >= 128 KB */
 ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case single-pass scenario */
 /* ZSTD_isError() :
  * Most ZSTD_* functions returning a size_t value can be tested for error,
index c3322852317ff6107fcdd2dd86614f84aa813f15..9d1862077a0a67464c9c6bda5ada1c7e26ea3ad3 100644 (file)
@@ -494,10 +494,8 @@ static void test_decompressBound(int tnb)
         char cBuffer[ZSTD_COMPRESSBOUND(sizeof(example))];
         size_t const cSize = ZSTD_compress(cBuffer, sizeof(cBuffer), example, sizeof(example), 0);
         CHECK_Z(cSize);
-        {   size_t const dbSize = ZSTD_decompressBound(cBuffer, cSize);
-            CHECK_Z(dbSize);
-            CHECK_EQ(dbSize, sizeof(example));
-    }   }
+        CHECK_EQ(ZSTD_decompressBound(cBuffer, cSize), (unsigned long long)sizeof(example));
+    }
 
     // Simple small compression without size : should provide 1 block size
     {   char cBuffer[ZSTD_COMPRESSBOUND(0)];