diff options
| author | Conrad Meyer <cem@FreeBSD.org> | 2019-11-06 06:42:00 +0000 |
|---|---|---|
| committer | Conrad Meyer <cem@FreeBSD.org> | 2019-11-06 06:42:00 +0000 |
| commit | ea68403922c3b53b00fc999fcb3eaef1feb50177 (patch) | |
| tree | 9870b0c695852e26fb9f8e19df8d7f5cb6616141 /examples/streaming_decompression.c | |
| parent | 90f4bdbe917eaf678feca2b0ff9647b5ae8bbb9d (diff) | |
Notes
Diffstat (limited to 'examples/streaming_decompression.c')
| -rw-r--r-- | examples/streaming_decompression.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/streaming_decompression.c b/examples/streaming_decompression.c index bcd861b756c1..d26b45b34c74 100644 --- a/examples/streaming_decompression.c +++ b/examples/streaming_decompression.c @@ -34,7 +34,10 @@ static void decompressFile_orDie(const char* fname) */ size_t const toRead = buffInSize; size_t read; + size_t lastRet = 0; + int isEmpty = 1; while ( (read = fread_orDie(buffIn, toRead, fin)) ) { + isEmpty = 0; ZSTD_inBuffer input = { buffIn, read, 0 }; /* Given a valid frame, zstd won't consume the last byte of the frame * until it has flushed all of the decompressed data of the frame. @@ -53,9 +56,24 @@ static void decompressFile_orDie(const char* fname) size_t const ret = ZSTD_decompressStream(dctx, &output , &input); CHECK_ZSTD(ret); fwrite_orDie(buffOut, output.pos, fout); + lastRet = ret; } } + if (isEmpty) { + fprintf(stderr, "input is empty\n"); + exit(1); + } + + if (lastRet != 0) { + /* The last return value from ZSTD_decompressStream did not end on a + * frame, but we reached the end of the file! We assume this is an + * error, and the input was truncated. + */ + fprintf(stderr, "EOF before end of stream: %zu\n", lastRet); + exit(1); + } + ZSTD_freeDCtx(dctx); fclose_orDie(fin); fclose_orDie(fout); |
