-
-
Notifications
You must be signed in to change notification settings - Fork 21
Fix inflate() flush modes and implement state.data_type #113
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
Fix inflate() flush modes and implement state.data_type #113
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work!
it's interesting that none of the zlib/zlib-ng tests catch these bugs. We'd like to add additional tests when we find that incorrect behavior slipped through.
zlib-rs/src/inflate.rs
Outdated
stream.data_type = | ||
state.bit_reader.bits_in_buffer() as i32 + | ||
if state.last { 64 } else { 0 } + | ||
if matches!(state.mode, Mode::Type) { 128 } else {0} + | ||
if matches!(state.mode, Mode::Len | Mode::CopyBlock) { 256 } else { 0 }; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we're only ever in one mode, I think a match
is nicer here. Also can tests be added that verify the behavior (probably from the libz-rs-sys` crate's test modules) versus zlib itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you're right. I will double-check zlib's original logic and correct it to one match. I will also put some tests together that demonstrate parity b/t libz-rs-sys and libz-sys
340aa9c
to
5480e0a
Compare
I split the changes into 3 commits and added a test which compares the stream positions and state data after each call to inflate(). It demonstrates that all three changes are needed for consistency |
5480e0a
to
706ff13
Compare
and implement the `Len_` state which is required for correct behavior with Trees flushing.
706ff13
to
659fb51
Compare
659fb51
to
d282f90
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #113 +/- ##
==========================================
+ Coverage 89.95% 90.59% +0.63%
==========================================
Files 36 36
Lines 9664 9767 +103
==========================================
+ Hits 8693 8848 +155
+ Misses 971 919 -52 ☔ View full report in Codecov by Sentry. |
After your changes, other tests were failing. Turns out this is what the Also for the future, our CI checks formatting and runs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for these fixes!
Thanks for merging and for your work on this crate! |
This PR address the following issues:
state.data_type
is always 0flush
is not respected ininflate()
#114TYPE
state toTYPE_DO
state