]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed bug #976, reported by @indygreg
authorYann Collet <cyan@fb.com>
Thu, 11 Jan 2018 04:33:45 +0000 (20:33 -0800)
committerYann Collet <cyan@fb.com>
Thu, 11 Jan 2018 04:33:45 +0000 (20:33 -0800)
constants in zstd.h should not depend on MIN() macro which existence is not guaranteed.

Added a test to check the specific constants.
The test is a bit too specific.
But I have found no way to control a more generic "are all macro already defined" condition,
especially as this is a valid construction (the missing macro might be defined later, intentionnally).

lib/zstd.h
tests/fuzzer.c

index c19496d02a83910e4cd21fc2d33055ce850b5fcb..a84490d995af79c268ead88d2589f107c2172da9 100644 (file)
@@ -379,9 +379,9 @@ ZSTDLIB_API size_t ZSTD_DStreamOutSize(void);   /*!< recommended size for output
 #define ZSTD_WINDOWLOG_MAX_64   31
 #define ZSTD_WINDOWLOG_MAX    ((unsigned)(sizeof(size_t) == 4 ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64))
 #define ZSTD_WINDOWLOG_MIN      10
-#define ZSTD_HASHLOG_MAX        MIN(ZSTD_WINDOWLOG_MAX, 30)
+#define ZSTD_HASHLOG_MAX      ((ZSTD_WINDOWLOG_MAX < 30) ? ZSTD_WINDOWLOG_MAX : 30)
 #define ZSTD_HASHLOG_MIN         6
-#define ZSTD_CHAINLOG_MAX       MIN(ZSTD_WINDOWLOG_MAX+1, 30)
+#define ZSTD_CHAINLOG_MAX     ((ZSTD_WINDOWLOG_MAX < 29) ? ZSTD_WINDOWLOG_MAX+1 : 30)
 #define ZSTD_CHAINLOG_MIN       ZSTD_HASHLOG_MIN
 #define ZSTD_HASHLOG3_MAX       17
 #define ZSTD_SEARCHLOG_MAX     (ZSTD_WINDOWLOG_MAX-1)
index 141bf65484c1e7d000f6bf5fcc9f55ce69ef2131..13e856be027deea06a54cb6d7f2db02df5aa1ceb 100644 (file)
@@ -65,11 +65,18 @@ static UTIL_time_t g_displayClock = UTIL_TIME_INITIALIZER;
             { g_displayClock = UTIL_getTime(); DISPLAY(__VA_ARGS__); \
             if (g_displayLevel>=4) fflush(stderr); } }
 
-/*-*******************************************************
-*  Fuzzer functions
-*********************************************************/
+
 #undef MIN
 #undef MAX
+void FUZ_bug976()
+{   /* these constants shall not depend on MIN() macro */
+    assert(ZSTD_HASHLOG_MAX < 31);
+    assert(ZSTD_CHAINLOG_MAX < 31);
+}
+
+/*-*******************************************************
+*  Internal functions
+*********************************************************/
 #define MIN(a,b) ((a)<(b)?(a):(b))
 #define MAX(a,b) ((a)>(b)?(a):(b))