]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fileio: Error in compression on read errors 1244/head
authorNick Terrell <terrelln@fb.com>
Tue, 17 Jul 2018 21:57:27 +0000 (14:57 -0700)
committerNick Terrell <terrelln@fb.com>
Tue, 17 Jul 2018 22:26:30 +0000 (15:26 -0700)
We can write a corrupted file if the input file errors during a read.
We should return a non-zero error code in this case.

programs/fileio.c

index b4eed28d1ae73f3186aa842821dd53c09d3ae830..85367fdfc3b2e22d0270717ad655c53f33138689 100644 (file)
@@ -797,6 +797,14 @@ FIO_compressZstdFrame(const cRess_t* ressPtr,
         }
     } while (directive != ZSTD_e_end);
 
+    if (ferror(srcFile)) {
+        EXM_THROW(26, "Read error : I/O error");
+    }
+    if (fileSize != UTIL_FILESIZE_UNKNOWN && *readsize != fileSize) {
+        EXM_THROW(27, "Read error : Incomplete read : %llu / %llu B",
+                (unsigned long long)*readsize, (unsigned long long)fileSize);
+    }
+
     return compressedfilesize;
 }