Fix bug of infinite loop on empty but marked as 'Inflated' entries. #44
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.
Description
Hi, working on camlzip I identified a bug that makes the
read_entry
function goes into an infinite loop for entries that are marked as 'Deflated' but are empty.In that very specific case, the recursive function
uncompr_finish
L116 goes infinite asinflate
always returnsfinished = false ; _
leading to an infinite loop.This case seems rare and unlikely, yet it seems that on windows systems it's not impossible and can sometimes happen, reason why I believe camlzip should consider this case as a valid possibility.
Reproduction step
I created a little file that reproduces the bug minimally.
It contains a single entry of an empty file.
I then modified the bits for the compression algorithm in both local and central headers for the file to be considered a
Inflated
.The result is the following :
You can find attached this file here :
demo.zip
Type of change
This PR is a bug fix.
When implementing I faced two options :
Taking a look at what other zip libraries are doing, such as Unzip and 7zip, I believe option 2 was the correct one, ensuring service continuity and security, therefore it is the one I implemented.
Style of change
I tried to stick as much as possible to the coding style, and tried to only modify the
read_entry
function to make the review easy.If you believe a heavier refactor would be more suitable I'll be more than happy to do it 😄 .
How Has This Been Tested?
If you believe adding a test over that would make sense I'll also do it with pleasure.