]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix : segfault in command line during automatic overwrite protection mode
authorYann Collet <yann.collet.73@gmail.com>
Tue, 21 Jun 2016 15:06:25 +0000 (17:06 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 21 Jun 2016 15:06:25 +0000 (17:06 +0200)
lib/compress/zbuff_compress.c
programs/fileio.c
programs/playTests.sh

index ff59525f0eb9d70251fbb68ab38d11a209d577eb..6ed5e52a449eb08acd37ceadf844e991c28891ed 100644 (file)
@@ -302,7 +302,7 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
         op += outSize;
         if (remainingToFlush) {
             *dstCapacityPtr = op-ostart;
-            return remainingToFlush + ZSTD_BLOCKHEADERSIZE;
+            return remainingToFlush + ZBUFF_endFrameSize;
         }
         /* create epilogue */
         zbc->stage = ZBUFFcs_final;
index 90041250d8bb20dc2896693453f529e748bb39d0..5e7b26dc6d3f5bffacfb6e8a9d9970e73b8a8c8d 100644 (file)
@@ -413,7 +413,7 @@ static int FIO_compressFilename_dstFile(cRess_t ress,
     int result;
 
     ress.dstFile = FIO_openDstFile(dstFileName);
-    if (ress.dstFile==0) { fclose(ress.srcFile); return 1; }
+    if (ress.dstFile==0) return 1;
 
     result = FIO_compressFilename_srcFile(ress, dstFileName, srcFileName, cLevel);
 
index a7edbeb94fcce5f5c28c940cd928e23fac8833b5..8afd9cb5a7f65ea7e8fe5ae79b5c260a2874c040 100755 (executable)
@@ -22,10 +22,12 @@ roundTripTest() {
 
 isWindows=false
 ECHO="echo"
+INTOVOID="/dev/null"
 case "$OS" in
   Windows*)
     isWindows=true
     ECHO="echo -e"
+    INTOVOID="nul"
     ;;
 esac
 
@@ -53,19 +55,21 @@ $ECHO "test : null-length file roundtrip"
 $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
 $ECHO "test : decompress file with wrong suffix (must fail)"
 $ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
+$ZSTD -df tmp && die "should have refused : wrong extension"
+$ECHO "test : decompress into stdout"
 $ZSTD -d tmpCompressed -c > tmpResult    # decompression using stdout
 $ZSTD --decompress tmpCompressed -c > tmpResult
 $ZSTD --decompress tmpCompressed --stdout > tmpResult
-if [ "$isWindows" = false ] ; then
-    $ZSTD -d    < tmp.zst > /dev/null    # combine decompression, stdin & stdout
-    $ZSTD -d  - < tmp.zst > /dev/null
-fi
-$ZSTD -dc   < tmp.zst > /dev/null
-$ZSTD -dc - < tmp.zst > /dev/null
+$ECHO "test : decompress from stdin into stdout"
+$ZSTD -dc   < tmp.zst > $INTOVOID   # combine decompression, stdin & stdout
+$ZSTD -dc - < tmp.zst > $INTOVOID
+$ZSTD -d    < tmp.zst > $INTOVOID   # implicit stdout when stdin is used
+$ZSTD -d  - < tmp.zst > $INTOVOID
+$ECHO "test : overwrite protection"
 $ZSTD -q tmp && die "overwrite check failed!"
+$ECHO "test : force overwrite"
 $ZSTD -q -f tmp
 $ZSTD -q --force tmp
-$ZSTD -df tmp && die "should have refused : wrong extension"
 $ECHO "test : file removal"
 $ZSTD -f --rm tmp
 ls tmp && die "tmp should no longer be present"
@@ -135,9 +139,9 @@ rm tmpSparse*
 
 $ECHO "\n**** multiple files tests **** "
 
-./datagen -s1        > tmp1 2> /dev/null
-./datagen -s2 -g100K > tmp2 2> /dev/null
-./datagen -s3 -g1M   > tmp3 2> /dev/null
+./datagen -s1        > tmp1 2> $INTOVOID
+./datagen -s2 -g100K > tmp2 2> $INTOVOID
+./datagen -s3 -g1M   > tmp3 2> $INTOVOID
 $ZSTD -f tmp*
 $ECHO "compress tmp* : "
 ls -ls tmp*