Skip to content

Commit f5bf4fd

Browse files
authored
Avoid ZLib::BufError by skipping empty chunks. (#98)
1 parent b7b0ba6 commit f5bf4fd

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Introduce `Protocol::HTTP::Middleware.load` method for loading middleware applications from files.
6+
- Prevent `ZLib::BufError` when deflating empty chunks by skipping deflation for empty chunks.
67

78
## v0.58.1
89

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)