Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zlib.inflate: detect truncated input instead of looping #47

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

xavierleroy
Copy link
Owner

@xavierleroy xavierleroy commented Sep 14, 2024

As reported in #45, truncated input can cause inflate to produce no output and to return "not finished" infinitely. This PR detects this case and fail cleanly with an exception instead of looping.

Closes: #45

Truncated input can cause `inflate` to produce no output and to return
"not finished" infinitely.

Detect this case and fail cleanly with an exception.

Note: it might be enough to fail at the first time `inflate` returns
"not finished but zero output produced".  Here we retry a few times
before failing, just in case.
Comment on lines +127 to +132
else
(* Gotcha: truncated input can cause an infinite loop where
[inflate] doesn't produce output and never returns "finished".
Raise an error after too many calls to [inflate] that produced
no output. *)
raise(Error("Zlib.uncompress", "truncated input data"))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: it would probably suffice to report an error as soon as used_out is 0 but finished is false. Here, we're retrying a few times before failing, just in case.

@xavierleroy xavierleroy merged commit 1bce445 into master Oct 4, 2024
@xavierleroy xavierleroy deleted the fix-short-inflate branch October 4, 2024 07:56
@Ant1-Provot
Copy link
Contributor

Thanks, I did not have time to work on it !
Have a good day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants