From b2580b6468a187887e0ffb032f3cd5a2ec7ef616 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Thu, 23 Jul 2026 17:13:49 -0500 Subject: [PATCH] metaUtils: require Z_STREAM_END when validating uncompressed data MET_PerformUncompression validated the number of bytes produced but not that the zlib stream terminated with Z_STREAM_END. When the output fills the destination buffer exactly, the next inflate() returns Z_BUF_ERROR (deliberately excluded from the diagnostic), the loop exits, and the byte-count check passes -- so a stream truncated at the size boundary is accepted without validating its trailing Adler-32 checksum. Reject the data unless inflate reported Z_STREAM_END, in addition to the existing byte-count check. This closes the exact-size truncation gap left by the byte-count check added in #142. Fixes #144. --- src/metaUtils.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/metaUtils.cxx b/src/metaUtils.cxx index 2244c81..e37635b 100644 --- a/src/metaUtils.cxx +++ b/src/metaUtils.cxx @@ -891,6 +891,12 @@ MET_PerformUncompression(const unsigned char * sourceCompressed, } while (d_stream.avail_out == 0); } while (err != Z_STREAM_END && err >= 0); inflateEnd(&d_stream); + if (err != Z_STREAM_END) + { + std::cerr << "MET_PerformUncompression: compressed stream did not terminate cleanly (zlib error " << err << ")" + << '\n'; + return false; + } if (dest_pos != uncompressedDataSize) { std::cerr << "MET_PerformUncompression: expected " << uncompressedDataSize << " bytes, produced " << dest_pos