fix : segfault in command line during automatic overwrite protection mode

dev
Yann Collet 2016-06-21 17:06:25 +02:00
parent bda68c253b
commit 391a128794
3 changed files with 16 additions and 12 deletions

View File

@ -302,7 +302,7 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
op += outSize; op += outSize;
if (remainingToFlush) { if (remainingToFlush) {
*dstCapacityPtr = op-ostart; *dstCapacityPtr = op-ostart;
return remainingToFlush + ZSTD_BLOCKHEADERSIZE; return remainingToFlush + ZBUFF_endFrameSize;
} }
/* create epilogue */ /* create epilogue */
zbc->stage = ZBUFFcs_final; zbc->stage = ZBUFFcs_final;

View File

@ -413,7 +413,7 @@ static int FIO_compressFilename_dstFile(cRess_t ress,
int result; int result;
ress.dstFile = FIO_openDstFile(dstFileName); 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); result = FIO_compressFilename_srcFile(ress, dstFileName, srcFileName, cLevel);

View File

@ -22,10 +22,12 @@ roundTripTest() {
isWindows=false isWindows=false
ECHO="echo" ECHO="echo"
INTOVOID="/dev/null"
case "$OS" in case "$OS" in
Windows*) Windows*)
isWindows=true isWindows=true
ECHO="echo -e" ECHO="echo -e"
INTOVOID="nul"
;; ;;
esac esac
@ -53,19 +55,21 @@ $ECHO "test : null-length file roundtrip"
$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout $ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
$ECHO "test : decompress file with wrong suffix (must fail)" $ECHO "test : decompress file with wrong suffix (must fail)"
$ZSTD -d tmpCompressed && die "wrong suffix error not detected!" $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 -d tmpCompressed -c > tmpResult # decompression using stdout
$ZSTD --decompress tmpCompressed -c > tmpResult $ZSTD --decompress tmpCompressed -c > tmpResult
$ZSTD --decompress tmpCompressed --stdout > tmpResult $ZSTD --decompress tmpCompressed --stdout > tmpResult
if [ "$isWindows" = false ] ; then $ECHO "test : decompress from stdin into stdout"
$ZSTD -d < tmp.zst > /dev/null # combine decompression, stdin & stdout $ZSTD -dc < tmp.zst > $INTOVOID # combine decompression, stdin & stdout
$ZSTD -d - < tmp.zst > /dev/null $ZSTD -dc - < tmp.zst > $INTOVOID
fi $ZSTD -d < tmp.zst > $INTOVOID # implicit stdout when stdin is used
$ZSTD -dc < tmp.zst > /dev/null $ZSTD -d - < tmp.zst > $INTOVOID
$ZSTD -dc - < tmp.zst > /dev/null $ECHO "test : overwrite protection"
$ZSTD -q tmp && die "overwrite check failed!" $ZSTD -q tmp && die "overwrite check failed!"
$ECHO "test : force overwrite"
$ZSTD -q -f tmp $ZSTD -q -f tmp
$ZSTD -q --force tmp $ZSTD -q --force tmp
$ZSTD -df tmp && die "should have refused : wrong extension"
$ECHO "test : file removal" $ECHO "test : file removal"
$ZSTD -f --rm tmp $ZSTD -f --rm tmp
ls tmp && die "tmp should no longer be present" ls tmp && die "tmp should no longer be present"
@ -135,9 +139,9 @@ rm tmpSparse*
$ECHO "\n**** multiple files tests **** " $ECHO "\n**** multiple files tests **** "
./datagen -s1 > tmp1 2> /dev/null ./datagen -s1 > tmp1 2> $INTOVOID
./datagen -s2 -g100K > tmp2 2> /dev/null ./datagen -s2 -g100K > tmp2 2> $INTOVOID
./datagen -s3 -g1M > tmp3 2> /dev/null ./datagen -s3 -g1M > tmp3 2> $INTOVOID
$ZSTD -f tmp* $ZSTD -f tmp*
$ECHO "compress tmp* : " $ECHO "compress tmp* : "
ls -ls tmp* ls -ls tmp*