Skip to content

Conversation

@martinemde
Copy link
Contributor

@martinemde martinemde commented Dec 22, 2023

When checking for eof?, read ahead until we can confidently say that either there is more content or the stream is finished. If reading ahead fills the z->buf, we are not at eof.

It's possible that only empty blocks or the footer remain to be read from the input stream. If eof? is only based on current status of the stream, a following read may produce no output, causing an EOFError because there's nothing left to return. This only happens for very specific gzip file lengths that hit exactly at a modulo of the read size, leaving only empty blocks and the footer remaining to be read.

Fixes #56

Only consider it eof if we read ahead and something fills the buf.
If not, we may only have empty blocks and the footer.

Fixes ruby#56
@martinemde martinemde force-pushed the martinemde/readpartial-fix branch from 524d9e0 to 437bea8 Compare January 22, 2024 23:54
@nobu nobu merged commit 78658aa into ruby:master Feb 22, 2024
@martinemde
Copy link
Contributor Author

@nobu thank you 🙇‍♂️

@martinemde martinemde deleted the martinemde/readpartial-fix branch February 22, 2024 16:48
k0kubun pushed a commit that referenced this pull request May 29, 2024
In Zlib::GzipReader#eof? check if we're actually at eof
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.

Zlib::GzipReader#readpartial until eof? causes EOFError

2 participants