Skip to content

Commit

Permalink
Raise DataError properly from Zlib::Inflate#inflate
Browse files Browse the repository at this point in the history
Similar fix as f8df1ab. For broken gzip
trailer, we should raise DataError even if the trailer is splitted into
multiple input chunks.

Reported by Atsuhiko Yamanaka at
https://twitter.com/#!/ymnk/status/109476173142179840 Thanks!
  • Loading branch information
Hiroshi Nakamura committed Sep 2, 2011
1 parent 91bf358 commit 1005f5a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/org/jruby/RubyZlib.java
Expand Up @@ -547,10 +547,10 @@ public void append(ByteList obj) {
flater.setInput(bytes);
input = new ByteList(bytes, false);
}
run(false);
} else {
input.append(obj);
}
run(false);
}

@JRubyMethod(name = "sync_point?")
Expand Down
18 changes: 18 additions & 0 deletions test/test_zlib.rb
Expand Up @@ -595,6 +595,15 @@ def test_wrong_length
z.inflate(gzip)
end
end

def test_wrong_length_split_trailer
gzip = "\x1f\x8b\x08\x00\x1a\x96\xe0\x4c\x00\x03\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36\x04\x00\x00"
z = Zlib::Inflate.new(Zlib::MAX_WBITS + 16)
assert_equal("hello", z.inflate(gzip))
assert_raise(Zlib::DataError) do
z.inflate("\x00")
end
end
end

# Test for MAX_WBITS + 32
Expand Down Expand Up @@ -686,4 +695,13 @@ def test_wrong_length
z.inflate(gzip)
end
end

def test_wrong_length_split_trailer
gzip = "\x1f\x8b\x08\x00\x1a\x96\xe0\x4c\x00\x03\xcb\x48\xcd\xc9\xc9\x07\x00\x86\xa6\x10\x36\x04\x00\x00"
z = Zlib::Inflate.new(Zlib::MAX_WBITS + 32)
assert_equal("hello", z.inflate(gzip))
assert_raise(Zlib::DataError) do
z.inflate("\x00")
end
end
end

0 comments on commit 1005f5a

Please sign in to comment.