Skip to content

Do not raise Zlib::BufError for a repeated flush with no new input - #175

Open
segiddins wants to merge 1 commit into
ruby:masterfrom
segiddins:segiddins/deflate-repeated-flush
Open

segiddins wants to merge 1 commit into
ruby:masterfrom
segiddins:segiddins/deflate-repeated-flush

Conversation

@segiddins

Copy link
Copy Markdown
Contributor

zlib's deflate() returns Z_BUF_ERROR when it is asked to flush again without having consumed any input since the previous flush of the same or higher rank, and the binding treated every code other than Z_OK and Z_STREAM_END as fatal. Nothing is lost in that case, and zlib's own gzflush() ignores the code for the same reason. The same happened for Zlib::Deflate#flush called twice and for GzipWriter#write("") with sync = true.

gz = Zlib::GzipWriter.new(StringIO.new(+""))
gz.write("a")
gz.flush
gz.flush
#=> Zlib::BufError (buffer error)

zlib's deflate() returns Z_BUF_ERROR when it is asked to flush again without having consumed any input since the previous flush of the same or higher rank, and the binding treated every code other than Z_OK and Z_STREAM_END as fatal. Nothing is lost in that case, and zlib's own gzflush() ignores the code for the same reason. The same happened for Zlib::Deflate#flush called twice and for GzipWriter#write("") with sync = true.

```ruby
gz = Zlib::GzipWriter.new(StringIO.new(+""))
gz.write("a")
gz.flush
gz.flush
#=> Zlib::BufError (buffer error)
```

Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant