]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[libzstd] Require ZSTD_MULTITHREAD to create a ZSTDMT_CCtx
authorNick Terrell <terrelln@fb.com>
Tue, 16 Apr 2019 05:49:44 +0000 (22:49 -0700)
committerNick Terrell <terrelln@fb.com>
Tue, 16 Apr 2019 06:04:46 +0000 (23:04 -0700)
ZSTDMT was broken when compiled without ZSTD_MULTITHREAD defined,
because `ZSTD_CCtx_setParameter(cctx, ZSTD_c_nbWorkers, nbWorkerss)`
failed. It was detected by the MSVC test which runs the fuzzer with
multithreading disabled.

This is a very niche use case of a deprecated API, because the API is
inefficient and synchronous, since `threading.h` will be synchronous.
Users almost certainly don't want this, and anyone who tested their code
should realize that it is broken. Therefore, I think it is safe to
require `ZSTD_MULTITHREAD` to be defined to use ZSTDMT.

CHANGELOG
lib/compress/zstdmt_compress.c
lib/compress/zstdmt_compress.h

index 61d0b3f56a383dfab314acdfc72af9805e1b3f25..bf04a8a131c065141cdb415b4bf3a8ce08cdefc6 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -5,6 +5,7 @@ api: Make ZSTD_e_flush and ZSTD_e_end block for maximum forward progress
 api: Rename ZSTD_CCtxParam_getParameter to ZSTD_CCtxParams_getParameter
 api: Rename ZSTD_CCtxParam_setParameter to ZSTD_CCtxParams_setParameter
 api: Don't export ZSTDMT functions from the shared library by default
+api: Require ZSTD_MULTITHREAD to be defined to use ZSTDMT
 api: Add ZSTD_decompressBound() to provide an upper bound on decompressed size by @shakeelrao
 api: Fix ZSTD_decompressDCtx() corner cases with a dictionary
 api: Move ZSTD_getDictID_*() functions to the stable section
index 4b29fb3e4ee2d04049ab62fcca195d3e9465a791..d0b4ee84a1d4b80ada035c0d6fd2013b879796bb 100644 (file)
@@ -874,6 +874,10 @@ ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers, ZSTD_customMem cMem)
     int initError;
     DEBUGLOG(3, "ZSTDMT_createCCtx_advanced (nbWorkers = %u)", nbWorkers);
 
+#ifndef ZSTD_MULTITHREAD
+    return NULL;
+#endif
+
     if (nbWorkers < 1) return NULL;
     nbWorkers = MIN(nbWorkers , ZSTDMT_NBWORKERS_MAX);
     if ((cMem.customAlloc!=NULL) ^ (cMem.customFree!=NULL))
index 8d274ce8d3c0b26767a0d6eba85e39fde2cbb3ff..12e6bcb3a3389345f813b6c11161a031cb60c205 100644 (file)
 /* Note : This is an internal API.
  *        These APIs used to be exposed with ZSTDLIB_API,
  *        because it used to be the only way to invoke MT compression.
- *        Now, it's recommended to use ZSTD_compress_generic() instead.
+ *        Now, it's recommended to use ZSTD_compress2 and ZSTD_compressStream2()
+ *        instead.
  *
  *        If you depend on these APIs and can't switch, then define
  *        ZSTD_LEGACY_MULTITHREADED_API when making the dynamic library.
  *        However, we may completely remove these functions in a future
  *        release, so please switch soon.
+ *
+ *        This API requires ZSTD_MULTITHREAD to be defined during compilation,
+ *        otherwise ZSTDMT_createCCtx*() will fail.
  */
 
 #ifdef ZSTD_LEGACY_MULTITHREADED_API
@@ -51,7 +55,9 @@
 
 /* ===   Memory management   === */
 typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
+/* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
 ZSTDMT_API ZSTDMT_CCtx* ZSTDMT_createCCtx(unsigned nbWorkers);
+/* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
 ZSTDMT_API ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,
                                                     ZSTD_customMem cMem);
 ZSTDMT_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);