summaryrefslogtreecommitdiff
path: root/src/archive
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2020-09-04 14:11:33 +0200
committerMax Kellermann <max@musicpd.org>2020-09-04 14:34:54 +0200
commit1f6a7d64622046f6b56c302c0f9ff34ae8c326c6 (patch)
tree54f4587a89b3927b53c7713650fb5fb12a1f14d8 /src/archive
parente44b953d9ab0cc0ea9b1ac07315feecc0b3c74d1 (diff)
archive/zzip: fix crash on corrupt ZIP file
Sometimes, zzip_file_read() returns 0 even though the end of the file was not reached. This causes assertion failures in DecoderBridge::Read(). Closes https://github.com/MusicPlayerDaemon/MPD/issues/935
Diffstat (limited to 'src/archive')
-rw-r--r--src/archive/plugins/ZzipArchivePlugin.cxx7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/archive/plugins/ZzipArchivePlugin.cxx b/src/archive/plugins/ZzipArchivePlugin.cxx
index c4ebbd582..75fa81c37 100644
--- a/src/archive/plugins/ZzipArchivePlugin.cxx
+++ b/src/archive/plugins/ZzipArchivePlugin.cxx
@@ -32,6 +32,8 @@
#include <zzip/zzip.h>
+#include <inttypes.h> /* for PRIoffset (PRIu64) */
+
struct ZzipDir {
ZZIP_DIR *const dir;
@@ -151,6 +153,11 @@ ZzipInputStream::Read(void *ptr, size_t read_size)
if (nbytes < 0)
throw std::runtime_error("zzip_file_read() has failed");
+ if (nbytes == 0 && !IsEOF())
+ throw FormatRuntimeError("Unexpected end of file %s"
+ " at %" PRIoffset " of %" PRIoffset,
+ GetURI(), GetOffset(), GetSize());
+
offset = zzip_tell(file);
return nbytes;
}