Commit 870e728a for libheif
commit 870e728a2b2d40232ad99d90f0cbe966513095a2
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Thu Mar 5 21:19:12 2026 +0100
fix edge case in zlib decompression
diff --git a/libheif/compression_zlib.cc b/libheif/compression_zlib.cc
index 7368e432..e3543d89 100644
--- a/libheif/compression_zlib.cc
+++ b/libheif/compression_zlib.cc
@@ -123,7 +123,12 @@ Result<std::vector<uint8_t>> do_inflate(const std::vector<uint8_t>& compressed_i
err = inflate(&strm, Z_NO_FLUSH);
if (err == Z_BUF_ERROR) {
- if (dst.size() >= 65536) { // TODO: make this a security limit
+ if (strm.avail_in == 0) {
+ // All input consumed; decompression is complete even without Z_STREAM_END
+ break;
+ }
+
+ if (dst.size() >= 256 * 1024 * 1024) { // TODO: make this a security limit
inflateEnd(&strm);
std::stringstream sstr;
sstr << "Error performing zlib inflate: maximum output buffer size exceeded\n";