]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
static dctx is incompatible with legacy support
authorYann Collet <yann.collet.73@gmail.com>
Sat, 27 May 2017 07:03:08 +0000 (00:03 -0700)
committerYann Collet <yann.collet.73@gmail.com>
Sat, 27 May 2017 07:03:08 +0000 (00:03 -0700)
documented, and runtime tested

doc/zstd_manual.html
lib/decompress/zstd_decompress.c
lib/zstd.h

index a4b59bc46b3775e5378211d7303ce312e5cc8561..156e7dd923a0c5b8a779a0d3d5fe2dccc043b00f 100644 (file)
@@ -718,7 +718,8 @@ size_t ZSTD_CDict_loadDictionary(ZSTD_CDict* cdict, const void* dict, size_t dic
  @return : pointer to ZSTD_DCtx*, or NULL if error (size too small)
   Note : zstd will never resize nor malloc() when using a static dctx.
          If it needs more memory than available, it will simply error out.
-  Note 2 : there is no corresponding "free" function.
+  Note 2 : static dctx is incompatible with legacy support
+  Note 3 : there is no corresponding "free" function.
            Since workspace was allocated externally, it must be freed externally.
   Limitation : currently not compatible with internal DDict creation,
                such as ZSTD_initDStream_usingDict().
index fe7446ab26dcba80f6ce9f0be987d00c2669aed9..a597243868d9b587a0e54532cc490935458317c1 100644 (file)
@@ -1586,6 +1586,8 @@ static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
             size_t decodedSize;
             size_t const frameSize = ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
             if (ZSTD_isError(frameSize)) return frameSize;
+            /* legacy support is incompatible with static dctx */
+            if (dctx->staticSize) return ERROR(memory_allocation);
 
             decodedSize = ZSTD_decompressLegacy(dst, dstCapacity, src, frameSize, dict, dictSize);
 
@@ -2258,8 +2260,11 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
     U32 someMoreWork = 1;
 
 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
-    if (zds->legacyVersion)
+    if (zds->legacyVersion) {
+        /* legacy support is incompatible with static dctx */
+        if (zds->staticSize) return ERROR(memory_allocation);
         return ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
+    }
 #endif
 
     while (someMoreWork) {
@@ -2277,6 +2282,8 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
                     if (legacyVersion) {
                         const void* const dict = zds->ddict ? zds->ddict->dictContent : NULL;
                         size_t const dictSize = zds->ddict ? zds->ddict->dictSize : 0;
+                        /* legacy support is incompatible with static dctx */
+                        if (zds->staticSize) return ERROR(memory_allocation);
                         CHECK_F(ZSTD_initLegacyStream(&zds->legacyContext, zds->previousLegacyVersion, legacyVersion,
                                                        dict, dictSize));
                         zds->legacyVersion = zds->previousLegacyVersion = legacyVersion;
index b1d8ecadd23fa2748d6766d10b8b89871bebb02f..3bbdb76f54c5d4966a4f12d222bf50e60575e34f 100644 (file)
@@ -844,7 +844,8 @@ ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem);
  * @return : pointer to ZSTD_DCtx*, or NULL if error (size too small)
  *  Note : zstd will never resize nor malloc() when using a static dctx.
  *         If it needs more memory than available, it will simply error out.
- *  Note 2 : there is no corresponding "free" function.
+ *  Note 2 : static dctx is incompatible with legacy support
+ *  Note 3 : there is no corresponding "free" function.
  *           Since workspace was allocated externally, it must be freed externally.
  *  Limitation : currently not compatible with internal DDict creation,
  *               such as ZSTD_initDStream_usingDict().