archive/bzip2: throw on unexpected input EOF
Don't silently return 0 when there is no more data, because this may crash the caller. And flush output even if input EOF has been reached.
This commit is contained in:
@@ -148,8 +148,7 @@ Bzip2InputStream::Read(void *ptr, size_t length)
|
||||
bzstream.avail_out = length;
|
||||
|
||||
do {
|
||||
if (!FillBuffer())
|
||||
return 0;
|
||||
const bool had_input = FillBuffer();
|
||||
|
||||
bz_result = BZ2_bzDecompress(&bzstream);
|
||||
|
||||
@@ -160,6 +159,9 @@ Bzip2InputStream::Read(void *ptr, size_t length)
|
||||
|
||||
if (bz_result != BZ_OK)
|
||||
throw std::runtime_error("BZ2_bzDecompress() has failed");
|
||||
|
||||
if (!had_input && bzstream.avail_out == length)
|
||||
throw std::runtime_error("Unexpected end of bzip2 file");
|
||||
} while (bzstream.avail_out == length);
|
||||
|
||||
nbytes = length - bzstream.avail_out;
|
||||
|
Reference in New Issue
Block a user