diff options
author | Max Kellermann <max@musicpd.org> | 2020-09-04 17:53:47 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-09-04 17:54:53 +0200 |
commit | 9e6c4f8d80c4c7b0af9b728fe7c710784534026c (patch) | |
tree | d64b547dc94e0f71b87663f33e7fc067da2b3d41 /src/archive/plugins | |
parent | 41b47f95c56c1ed51e48b91a0a781acba0d1cd95 (diff) |
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.
Diffstat (limited to 'src/archive/plugins')
-rw-r--r-- | src/archive/plugins/Bzip2ArchivePlugin.cxx | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/archive/plugins/Bzip2ArchivePlugin.cxx b/src/archive/plugins/Bzip2ArchivePlugin.cxx index 493ffec88..0228fa743 100644 --- a/src/archive/plugins/Bzip2ArchivePlugin.cxx +++ b/src/archive/plugins/Bzip2ArchivePlugin.cxx @@ -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; |