From ee1ed78fcb3d53182c944940e16e697c94087a8b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 30 Sep 2017 11:08:50 -0700 Subject: [PATCH 1/3] fix proper naming on FSE_createCTable() arguments in fse.h --- lib/common/fse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/fse.h b/lib/common/fse.h index 1c44f8375..afd780196 100644 --- a/lib/common/fse.h +++ b/lib/common/fse.h @@ -184,7 +184,7 @@ FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize, const sh /*! Constructor and Destructor of FSE_CTable. Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */ typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */ -FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned tableLog, unsigned maxSymbolValue); +FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog); FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct); /*! FSE_buildCTable(): From c5d6dde502e4e30c7de4476e82b459361fe2f486 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Sat, 30 Sep 2017 14:17:32 -0700 Subject: [PATCH 2/3] Don't `size -= 1` in ZSTD_adjustCParams() The window size could end up too small if the source size is 2^n + 1. Credit to OSS-Fuzz --- lib/compress/zstd_compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 4c2254abe..51cdeaf03 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -651,7 +651,7 @@ ZSTD_compressionParameters ZSTD_adjustCParams_internal(ZSTD_compressionParameter if (dictSize && (srcSize+1<2) /* srcSize unknown */ ) srcSize = minSrcSize; /* presumed small when there is a dictionary */ - else + else if (srcSize == 0) srcSize -= 1; /* unknown 0 => -1ULL : presumed large */ /* resize windowLog if input is small enough, to use less memory */ From dc404119e5377ce18e49bedeeab3f0ff8b815d87 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 30 Sep 2017 15:02:40 -0700 Subject: [PATCH 3/3] ZSTD_adjustCParams_internal : minor optimization --- lib/compress/zstd_compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 51cdeaf03..2511ab29e 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -652,7 +652,7 @@ ZSTD_compressionParameters ZSTD_adjustCParams_internal(ZSTD_compressionParameter if (dictSize && (srcSize+1<2) /* srcSize unknown */ ) srcSize = minSrcSize; /* presumed small when there is a dictionary */ else if (srcSize == 0) - srcSize -= 1; /* unknown 0 => -1ULL : presumed large */ + srcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* 0 == unknown : presumed large */ /* resize windowLog if input is small enough, to use less memory */ if ( (srcSize < maxWindowResize)