]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix dctx initialization within ZSTD_decompress in stack mode 1187/head
authorYann Collet <cyan@fb.com>
Thu, 14 Jun 2018 14:22:24 +0000 (10:22 -0400)
committerYann Collet <cyan@fb.com>
Thu, 14 Jun 2018 14:22:24 +0000 (10:22 -0400)
when ZSTD_HEAPMODE=0 (which is not default).

Also : added an associated test (test-fuzzer-stackmode)
run on travis CI

fix #1186

.travis.yml
lib/decompress/zstd_decompress.c
tests/Makefile

index b01805bee29c55e073ce67d284a7eadbd98d0da1..8c5eb70f2b6d780bca32e8422494533c9ba47195 100644 (file)
@@ -20,14 +20,18 @@ matrix:
     - env: Cmd='make clang38install && CC=clang-3.8 make clean msan-fuzztest'
     - env: Cmd='make clang38install && CC=clang-3.8 make clean tsan-test-zstream'
 
+    - env: Cmd='make -C tests test-fuzzer-stackmode'
+
     - env: Cmd='make valgrindinstall && make -C tests clean valgrindTest'
 
     - env: Cmd='make arminstall && make armfuzz'
+
 # Following test is disabled, as there is a bug in Travis' ld
 # preventing aarch64 compilation to complete.
 # > collect2: error: ld terminated with signal 11 [Segmentation fault], core dumped
 # to be re-enabled in a few commit, as it's possible that a random code change circumvent the ld bug
 #    - env: Cmd='make arminstall && make aarch64fuzz'
+
     - env: Cmd='make ppcinstall && make ppcfuzz'
     - env: Cmd='make ppcinstall && make ppc64fuzz'
     - env: Cmd='make -j uasanregressiontest && make clean && make -j msanregressiontest'
@@ -35,6 +39,7 @@ matrix:
     - env: Cmd='make lz4install && make -C tests test-lz4'
 
     - env: Cmd='bash tests/libzstd_partial_builds.sh'
+
     # tag-specific test
     - if: tag =~ ^v[0-9]\.[0-9]
       env: Cmd='make -C tests checkTag && tests/checkTag $TRAVIS_BRANCH'
index 030b74839d13f8e0db966037c9559da8559b82c4..f65d85662f872e648dddafa404d2f0513dca4cf0 100644 (file)
@@ -192,6 +192,8 @@ static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx)
     dctx->inBuffSize  = 0;
     dctx->outBuffSize = 0;
     dctx->streamStage = zdss_init;
+    dctx->legacyContext = NULL;
+    dctx->previousLegacyVersion = 0;
     dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
 }
 
@@ -215,8 +217,6 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
     {   ZSTD_DCtx* const dctx = (ZSTD_DCtx*)ZSTD_malloc(sizeof(*dctx), customMem);
         if (!dctx) return NULL;
         dctx->customMem = customMem;
-        dctx->legacyContext = NULL;
-        dctx->previousLegacyVersion = 0;
         ZSTD_initDCtx_internal(dctx);
         return dctx;
     }
@@ -1996,6 +1996,7 @@ size_t ZSTD_decompress(void* dst, size_t dstCapacity, const void* src, size_t sr
     return regenSize;
 #else   /* stack mode */
     ZSTD_DCtx dctx;
+    ZSTD_initDCtx_internal(&dctx);
     return ZSTD_decompressDCtx(&dctx, dst, dstCapacity, src, srcSize);
 #endif
 }
index c1482bc9c3c442c792e943cd718fb5d753846b6e..792ee9efe613fe25c1b53cde326989d909452bb6 100644 (file)
@@ -360,6 +360,9 @@ test-fullbench32: fullbench32 datagen
 test-fuzzer: fuzzer
        $(QEMU_SYS) ./fuzzer -v $(FUZZERTEST) $(FUZZER_FLAGS)
 
+test-fuzzer-stackmode: MOREFLAGS += -DZSTD_HEAPMODE=0
+test-fuzzer-stackmode: test-fuzzer
+
 test-fuzzer32: fuzzer32
        $(QEMU_SYS) ./fuzzer32 -v $(FUZZERTEST) $(FUZZER_FLAGS)