Skip to content

Commit 7b18ede

Browse files
committed
Avoid ZLib::BufError by skipping empty chunks.
1 parent ef20d4d commit 7b18ede

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

lib/protocol/http/body/deflate.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,19 @@ def read
113113
return if @stream.finished?
114114

115115
# The stream might have been closed while waiting for the chunk to come in.
116-
if chunk = super
117-
@input_length += chunk.bytesize
118-
119-
chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
120-
121-
@output_length += chunk.bytesize
122-
123-
return chunk
124-
elsif !@stream.closed?
116+
while chunk = super
117+
unless chunk.empty?
118+
@input_length += chunk.bytesize
119+
120+
chunk = @stream.deflate(chunk, Zlib::SYNC_FLUSH)
121+
122+
@output_length += chunk.bytesize
123+
124+
return chunk
125+
end
126+
end
127+
128+
if !@stream.closed?
125129
chunk = @stream.finish
126130

127131
@output_length += chunk.bytesize

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.
6+
37
## v0.55.0
48

59
- **Breaking**: Move `Protocol::HTTP::Header::QuotedString` to `Protocol::HTTP::QuotedString` for better reusability.

test/protocol/http/body/deflate.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,13 @@
7272
)
7373
end
7474
end
75+
76+
with "empty chunks" do
77+
let(:body) {Protocol::HTTP::Body::Buffered.new(["", "bar", ""])}
78+
79+
it "can read empty chunks" do
80+
expect(decompressed_body.read).to be == "bar"
81+
expect(decompressed_body.read).to be == nil
82+
end
83+
end
7584
end

0 commit comments

Comments
 (0)