Skip to content

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

Merged
merged 4 commits into from
Jun 13, 2024

Conversation

cjgriscom
Copy link
Contributor

@cjgriscom cjgriscom commented Jun 12, 2024

This PR address the following issues:

Copy link
Collaborator

@folkertdev folkertdev left a 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.

Comment on lines 1956 to 1983
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 };

Copy link
Collaborator

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?

Copy link
Contributor Author

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

@cjgriscom cjgriscom force-pushed the inflate-flush-block branch from 340aa9c to 5480e0a Compare June 13, 2024 01:38
@cjgriscom
Copy link
Contributor Author

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

@folkertdev folkertdev force-pushed the inflate-flush-block branch from 5480e0a to 706ff13 Compare June 13, 2024 09:17
and implement the `Len_` state which is required for correct behavior
with Trees flushing.
@folkertdev folkertdev force-pushed the inflate-flush-block branch from 706ff13 to 659fb51 Compare June 13, 2024 09:20
@folkertdev folkertdev force-pushed the inflate-flush-block branch from 659fb51 to d282f90 Compare June 13, 2024 09:27
Copy link

codecov bot commented Jun 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.59%. Comparing base (52e1628) to head (d282f90).
Report is 9 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@folkertdev
Copy link
Collaborator

After your changes, other tests were failing. Turns out this is what the LEN_ state is for. It looks really weird otherwise because it does no real work, just falls throught, but apparently that state is important for the correct behavior of Flush::Trees.

Also for the future, our CI checks formatting and runs cargo clippy (also on tests). We advise you run those tools locally at every commit, that'll save a bunch of back-and-forth with CI.

Copy link
Collaborator

@folkertdev folkertdev left a 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!

@folkertdev folkertdev merged commit 05f0209 into trifectatechfoundation:main Jun 13, 2024
13 checks passed
@cjgriscom
Copy link
Contributor Author

Thanks for merging and for your work on this crate!

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