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:
Max Kellermann 2020-09-04 17:53:47 +02:00
parent 41b47f95c5
commit 9e6c4f8d80
2 changed files with 6 additions and 2 deletions

2
NEWS
View File

@ -3,6 +3,8 @@ ver 0.21.26 (not yet released)
- osx: fix crash bug - osx: fix crash bug
- sles: support floating point samples - sles: support floating point samples
* archive * archive
- bzip2: fix crash on corrupt bzip2 file
- bzip2: flush output at end of input file
- zzip: fix crash on corrupt ZIP file - zzip: fix crash on corrupt ZIP file
* decoder * decoder
- sndfile: fix lost samples at end of file - sndfile: fix lost samples at end of file

View File

@ -148,8 +148,7 @@ Bzip2InputStream::Read(void *ptr, size_t length)
bzstream.avail_out = length; bzstream.avail_out = length;
do { do {
if (!FillBuffer()) const bool had_input = FillBuffer();
return 0;
bz_result = BZ2_bzDecompress(&bzstream); bz_result = BZ2_bzDecompress(&bzstream);
@ -160,6 +159,9 @@ Bzip2InputStream::Read(void *ptr, size_t length)
if (bz_result != BZ_OK) if (bz_result != BZ_OK)
throw std::runtime_error("BZ2_bzDecompress() has failed"); 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); } while (bzstream.avail_out == length);
nbytes = length - bzstream.avail_out; nbytes = length - bzstream.avail_out;