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

Partial gzip header breaks decoding #320

Closed
jongiddy opened this issue Oct 24, 2022 · 2 comments · Fixed by #323
Closed

Partial gzip header breaks decoding #320

jongiddy opened this issue Oct 24, 2022 · 2 comments · Fixed by #323

Comments

@jongiddy
Copy link
Contributor

The read_gz_header_part function returns an Err if the first 10 bytes of the gzip header are not present or if the FEXTRA flag is set and the extra fields are not present. Returning an Err causes GzDecoder::write to keep the buffer and wait for more data to complete the header.

However, if the header contains an optional filename or comment but they are not completely contained in the buffer, then a valid header is created, missing data from the optional sections. The next write call will treat the remaining header as encoded data and attempt to unzip it.

The problem occurs because for byte in r.bytes() ends the iteration when the end of the buffer is found, falling through to the next state.

If this happens, the code should return Err(io::ErrorKind::UnexpectedEof) to allow a subsequent write to complete the header.

@jongiddy
Copy link
Contributor Author

Anyone trying to fix this issue probably needs to look at the discussion here: https://github.com/rust-lang/flate2-rs/pull/278/files#r676719137

@jongiddy
Copy link
Contributor Author

jongiddy commented Oct 25, 2022

#265 is possibly linked - missing filename in header and problems decompressing.

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 a pull request may close this issue.

1 participant