]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed continuation context
authorYann Collet <cyan@fb.com>
Sun, 28 Aug 2016 17:00:49 +0000 (10:00 -0700)
committerYann Collet <cyan@fb.com>
Sun, 28 Aug 2016 17:00:49 +0000 (10:00 -0700)
lib/decompress/zstd_decompress.c
lib/legacy/zstd_v07.c
programs/fileio.c
programs/zstdcli.c

index 97adec20502af3d3cd6f92f0a4ed1fd3a9a2df6e..e540e3fe9be27d0d9455c23737ca5673a7d8c5c0 100644 (file)
@@ -1399,7 +1399,7 @@ size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t di
 {
     zds->stage = zdss_loadHeader;
     zds->lhSize = zds->inPos = zds->outStart = zds->outEnd = 0;
-    if ((dict != zds->dictSource) || (dictSize != zds->dictSize)) {   /* new dictionary */
+    if ((dict != zds->dictSource) | (dictSize != zds->dictSize)) {   /* new dictionary */
         if (dictSize > zds->dictSize) {
             if (zds->dictContent) zds->customMem.customFree(zds->customMem.opaque, zds->dictContent);
             zds->dictContent = zds->customMem.customAlloc(zds->customMem.opaque, dictSize);
@@ -1457,7 +1457,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
 
 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
     if (zds->legacyVersion)
-        return ZSTD_decompressLegacyStream(&zds->legacyContext, zds->legacyVersion, output, input);
+        return ZSTD_decompressLegacyStream(zds->legacyContext, zds->legacyVersion, output, input);
 #endif
 
     while (someMoreWork) {
index c4ccd24c976b2738a0c6601ad8a5be0d407a8a22..16c09af43aab27a6ae92d1887e23a88ddd08bc80 100644 (file)
@@ -4643,9 +4643,9 @@ size_t ZBUFFv07_decompressContinue(ZBUFFv07_DCtx* zbd,
 
         case ZBUFFds_loadHeader :
             {   size_t const hSize = ZSTDv07_getFrameParams(&(zbd->fParams), zbd->headerBuffer, zbd->lhSize);
+                if (ZSTDv07_isError(hSize)) return hSize;
                 if (hSize != 0) {
                     size_t const toLoad = hSize - zbd->lhSize;   /* if hSize!=0, hSize > zbd->lhSize */
-                    if (ZSTDv07_isError(hSize)) return hSize;
                     if (toLoad > (size_t)(iend-ip)) {   /* not enough input to load full header */
                         memcpy(zbd->headerBuffer + zbd->lhSize, ip, iend-ip);
                         zbd->lhSize += iend-ip;
@@ -4685,6 +4685,7 @@ size_t ZBUFFv07_decompressContinue(ZBUFFv07_DCtx* zbd,
                         if (zbd->outBuff == NULL) return ERROR(memory_allocation);
             }   }   }
             zbd->stage = ZBUFFds_read;
+            /* pass-through */
 
         case ZBUFFds_read:
             {   size_t const neededInSize = ZSTDv07_nextSrcSizeToDecompress(zbd->zd);
index 93ecaec3fc0c57d3887c964c72aa6f309b25814d..00cb31baa02ccb390f06ff89f18cb8da4dcd593d 100644 (file)
 */
 
 
+/* *************************************
+ *  Tuning options
+ ***************************************/
+#ifndef ZSTD_LEGACY_SUPPORT
+/* LEGACY_SUPPORT :
+ *  decompressor can decode older formats (starting from Zstd 0.1+) */
+#  define ZSTD_LEGACY_SUPPORT 1
+#endif
+
+
 /* *************************************
 *  Compiler Options
 ***************************************/
 #define ZSTD_STATIC_LINKING_ONLY   /* ZSTD_magicNumber, ZSTD_frameHeaderSize_max */
 #include "zstd.h"
 
+#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1)
+#  include "zstd_legacy.h"    /* ZSTD_isLegacy */
+#endif
+
 
 /*-*************************************
 *  OS-specific Includes
@@ -688,7 +702,11 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName)
         readSomething = 1;
         if (sizeCheck != toRead) { DISPLAY("zstd: %s: unknown header \n", srcFileName); fclose(srcFile); return 1; }  /* srcFileName is empty */
         {   U32 const magic = MEM_readLE32(ress.srcBuffer);
-            if (((magic & 0xFFFFFFF0U) != ZSTD_MAGIC_SKIPPABLE_START) & (magic != ZSTD_MAGICNUMBER)) {
+            if (((magic & 0xFFFFFFF0U) != ZSTD_MAGIC_SKIPPABLE_START) & (magic != ZSTD_MAGICNUMBER)
+#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
+                  & (!ZSTD_isLegacy(ress.srcBuffer, toRead))
+#endif
+                ) {
                 if ((g_overwrite) && !strcmp (srcFileName, stdinmark)) {  /* pass-through mode */
                     unsigned const result = FIO_passThrough(dstFile, srcFile, ress.srcBuffer, ress.srcBufferSize);
                     if (fclose(srcFile)) EXM_THROW(32, "zstd: %s close error", srcFileName);  /* error should never happen */
index c03d6dde4b316569b9067aae634d578bc623ee68..64d2c2a972a81ed85c033eaa73434851106e381b 100644 (file)
@@ -1,3 +1,4 @@
+
 /*
   zstdcli - Command Line Interface (cli) for zstd
   Copyright (C) Yann Collet 2014-2016