Skip to content

Commit

Permalink
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spec/std/zlib/inflate_spec.cr
Original file line number Diff line number Diff line change
@@ -54,5 +54,16 @@ module Zlib
inflate = Inflate.new(io)
inflate.read_byte.should be_nil
end

it "should not freeze when reading empty slice" do
io = MemoryIO.new
"789c2bc9c82c5600a2448592d4e21285e292a2ccbc74054520e00200854f087b".scan(/../).each do |match|
io.write_byte match[0].to_u8(16)
end
io.rewind
inflate = Inflate.new(io)
slice = Slice(UInt8).new(0)
inflate.read(slice).should eq(0)
end
end
end
2 changes: 2 additions & 0 deletions src/zlib/inflate.cr
Original file line number Diff line number Diff line change
@@ -72,6 +72,8 @@ class Zlib::Inflate
def read(slice : Slice(UInt8))
check_open

return 0 if slice.empty?

while true
if @stream.avail_in == 0
@stream.next_in = @buf.to_unsafe

0 comments on commit b987df1

Please sign in to comment.