]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed --test on zero-length files, reported by @amnilsson
authorYann Collet <yann.collet.73@gmail.com>
Tue, 26 Jul 2016 13:39:31 +0000 (15:39 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 26 Jul 2016 13:49:24 +0000 (15:49 +0200)
lib/legacy/zstd_v07.c
programs/fileio.c
programs/playTests.sh

index 62213997fa6904d906442d57ca462d946fa510cd..d95fd438eea13d1a1a103492118377e40fed3a6a 100644 (file)
@@ -4060,7 +4060,7 @@ static seq_t ZSTDv07_decodeSequence(seqState_t* seqState)
 }
 
 
-FORCE_INLINE
+static
 size_t ZSTDv07_execSequence(BYTE* op,
                                 BYTE* const oend, seq_t sequence,
                                 const BYTE** litPtr, const BYTE* const litLimit_w,
index 3233be2e5ea818e4a1dbb5adb855460d3426ee57..f8542f78791eb63b2fba36982be2803d8ec3b51d 100644 (file)
@@ -696,7 +696,10 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName)
         /* check magic number -> version */
         size_t const toRead = 4;
         size_t const sizeCheck = fread(ress.srcBuffer, (size_t)1, toRead, srcFile);
-        if (sizeCheck==0) break;   /* no more input */
+        if (sizeCheck==0) {
+            if (filesize==0) { DISPLAY("zstd: %s: unexpected end of file\n", srcFileName); return 1; }  /* srcFileName is empty */
+            break;   /* no more input */
+        }
         if (sizeCheck != toRead) EXM_THROW(31, "zstd: %s read error : cannot read header", srcFileName);
         {   U32 const magic = MEM_readLE32(ress.srcBuffer);
 #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
index 7550608140d66ef1feb456e655672a42080dd675..ef44f7bdfb5618a84bce8b24ad90954bb067bafa 100755 (executable)
@@ -209,6 +209,8 @@ $ZSTD -t * && die "bad files not detected !"
 $ZSTD -t tmp1 && die "bad file not detected !"
 cp tmp1 tmp2.zst
 $ZSTD -t tmp2.zst && die "bad file not detected !"
+./datagen -g0 > tmp3
+$ZSTD -t tmp3 && die "bad file not detected !"   # detects 0-sized files as bad
 $ECHO "test --rm and --test combined "
 $ZSTD -t --rm tmp1.zst
 ls -ls tmp1.zst  # check file is still present