fixed --test on zero-length files, reported by @amnilsson

This commit is contained in:
Yann Collet
2016-07-26 15:49:24 +02:00
parent 9cebec21e1
commit 7adc2328a3
3 changed files with 7 additions and 2 deletions
+4 -1
View 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)