fix(zstream): fail on truncated input instead of looping forever - #7346
Open
weihanglo wants to merge 3 commits into
Open
fix(zstream): fail on truncated input instead of looping forever#7346weihanglo wants to merge 3 commits into
weihanglo wants to merge 3 commits into
Conversation
`inflate()` reports `Z_BUF_ERROR` when a truncated stream exhausts its input before reaching `Z_STREAM_END`. The stock `zstream_seterr` suggests treating that as non-fatal so callers can retry with more input or output space. However, the drain loop in `git_zstream_get_output` can supply neither because * output space is still available * input is only refilled outside the loop It would leads to zero-progress forever. The problematic behavior was found in `git_odb_read` on a truncated loose object. The proposed fix here: Detect the stuck state in the drain loop and report an error.
When inflating a stream, if the stream is truncated midway, it must fail rather than loop forever.
This ensure that `git_odb_read` fails when reading truncated loose object. If you move this before the fix commit, this loops forever
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.
What does this fix?
Fixes #7342.
inflate()reportsZ_BUF_ERRORwhen a truncated stream exhausts its input before reachingZ_STREAM_END.The stock
zstream_seterrsuggests treating that as non-fatal so callers can retry with more input or output space.libgit2/deps/zlib/zlib.h
Lines 513 to 515 in d535450
However, the drain loop in
git_zstream_get_outputcan supply neither becauseIt would leads to zero-progress forever.
The problematic behavior was found in
git_odb_readon a truncated loose object.The proposed fix here: Detect the stuck state in the drain loop and report an error.
How to review
Commit by commit.
cb4c344 the odb test will loop forever if you drop the first fix commit.
🤖 LLM disclosure: This bug was found by LLM. Tests were generated by LLM. I've review carefully all the generated content and analysis.