]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed null-length round trip
authorYann Collet <yann.collet.73@gmail.com>
Tue, 26 Jul 2016 14:44:09 +0000 (16:44 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 26 Jul 2016 14:44:09 +0000 (16:44 +0200)
programs/fileio.c

index f8542f78791eb63b2fba36982be2803d8ec3b51d..ee5efa9e395ae4cd9fe9a2409b4d28884e716b56 100644 (file)
@@ -683,6 +683,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName)
     unsigned long long filesize = 0;
     FILE* const dstFile = ress.dstFile;
     FILE* srcFile;
+    unsigned readSomething = 0;
 
     if (UTIL_isDirectory(srcFileName)) {
         DISPLAYLEVEL(1, "zstd: %s is a directory -- ignored \n", srcFileName);
@@ -697,9 +698,10 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName)
         size_t const toRead = 4;
         size_t const sizeCheck = fread(ress.srcBuffer, (size_t)1, toRead, srcFile);
         if (sizeCheck==0) {
-            if (filesize==0) { DISPLAY("zstd: %s: unexpected end of file\n", srcFileName); return 1; }  /* srcFileName is empty */
+            if (readSomething==0) { DISPLAY("zstd: %s: unexpected end of file\n", srcFileName); return 1; }  /* srcFileName is empty */
             break;   /* no more input */
         }
+        readSomething = 1;
         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)