deflate: Better Huffman.construct errors and error handling#9880
Merged
andrewrk merged 2 commits intoziglang:masterfrom Oct 4, 2021
Merged
deflate: Better Huffman.construct errors and error handling#9880andrewrk merged 2 commits intoziglang:masterfrom
andrewrk merged 2 commits intoziglang:masterfrom
Conversation
This brings construct error handling in line with puff.c
squeek502
commented
Oct 2, 2021
Member
Author
LemonBoy
reviewed
Oct 2, 2021
| self.last_code = codes[PREFIX_LUT_BITS + 1]; | ||
| self.last_index = offset[PREFIX_LUT_BITS + 1] - self.count[PREFIX_LUT_BITS + 1]; | ||
|
|
||
| if (left > 0) |
Contributor
There was a problem hiding this comment.
Minor nit, why not move the check below the loop that computes left?
Member
Author
There was a problem hiding this comment.
I didn't want to potentially leave self.last_code/self.last_index uninitialized since error.IncompleteSet is not always treated as an error by the caller, and if decode uses those fields when uninitialized it can lead to index-out-of-bounds/UB.
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.
This brings Huffman.construct error handling in line with puff.c (I'm assuming we're okay with treating
puff.cas an oracle). The error names and logic are from puff.c (and zlib's inflate.c uses the same terminology).Note: I am planning to add relevant test cases soon. EDIT: Done
This is the last piece of the puzzle for getting the deflate.zig <-> puff.c comparison fuzzer (which checks that all inputs either give the same inflated output or give errors in both implementations) to run cleanly (so far at least). Other required puzzle pieces:
cc @LemonBoy @mattbork