metaUtils: require Z_STREAM_END when validating uncompressed data#145
Merged
dzenanz merged 1 commit intoJul 23, 2026
Merged
Conversation
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 Kitware#142. Fixes Kitware#144.
hjmjohnson
marked this pull request as ready for review
July 23, 2026 22:17
Contributor
Author
|
@dzenanz I don't have merge capabilities here. This was a possible failure case found by GrepTile. |
dzenanz
approved these changes
Jul 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Require
Z_STREAM_ENDinMET_PerformUncompression, not just the expected byte count, so a compressed stream truncated exactly at the declared output size is rejected instead of silently accepted. Fixes #144; hardens the byte-count check from #142.Root cause
When the decompressed data fills the destination buffer exactly, the last
inflate()returnsZ_OKand the next call (withavail_out == 0) returnsZ_BUF_ERROR. That is< 0, so the loop exits — butZ_BUF_ERRORis deliberately excluded from the "Uncompress failed" diagnostic (treated as non-fatal "buffer full"). Control reaches the final check withdest_pos == uncompressedDataSizeand the function returnstrue, even thoughZ_STREAM_ENDwas never reached and the trailing Adler-32 checksum was never validated.Adding an explicit
err != Z_STREAM_ENDrejection guarantees the entire stream (including its trailer) was consumed, closing the exact-size-truncation gap while keeping the informative byte-count message for the short-read case.