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

Fix Compress::Gzip::Header to check for CRC16 #14791

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kojix2
Copy link
Contributor

@kojix2 kojix2 commented Jul 7, 2024

I wrote code to check the value of CRC16 if the Gzip header flag contains an HCRC.

This solves part of #14789

@kojix2 kojix2 changed the title Gzipcheckhcrc Fix Compress::Gzip::Header to check for CRC16 Jul 7, 2024
@kojix2
Copy link
Contributor Author

kojix2 commented Jul 7, 2024

Feel free to correct me if you have a better way to write this.

@straight-shoota
Copy link
Member

straight-shoota commented Jul 7, 2024

As always, this change is void if there's no spec to ensure its functionality. We'll need at least one example with an invalid CRC and a test to ensure it raises.

Capturing the header bytes in an array seems very inefficient. It also shouldn't be necessary to do in one go.
Instead of passing the entire data to CRC32.checksum, we can update the checksum with individual bytes or slices as we read them. The result should be identical.
We can either instantiate the CRC32 class and append data bits, or use the .initial and .update class methods. The latter is used in the Gzip::Reader and Gzip::Writer implementations, for example.

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

Successfully merging this pull request may close these issues.

None yet

3 participants