From 4e706d7f2cb79df257809b45c033b3bcf5822edf Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Tue, 17 Jul 2018 14:57:27 -0700 Subject: [PATCH] fileio: Error in compression on read errors 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/programs/fileio.c b/programs/fileio.c index b4eed28d1..85367fdfc 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -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; } -- 2.47.2