ruby-changes:30641
From: drbrain <ko1@a...>
Date: Thu, 29 Aug 2013 05:36:27 +0900 (JST)
Subject: [ruby-changes:30641] drbrain:r42720 (trunk): * ext/zlib/zlib.c (zstream_run): Fix handling of deflate streams that
drbrain 2013-08-29 05:36:21 +0900 (Thu, 29 Aug 2013) New Revision: 42720 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42720 Log: * ext/zlib/zlib.c (zstream_run): Fix handling of deflate streams that need a dictionary but are being decompressed by Zlib::Inflate.inflate (which has no option to set a dictionary). Now Zlib::NeedDict is raised instead of crashing. [ruby-trunk - Bug #8829] * test/zlib/test_zlib.rb (TestZlibInflate): Test for the above. Modified files: trunk/ChangeLog trunk/ext/zlib/zlib.c trunk/test/zlib/test_zlib.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 42719) +++ ChangeLog (revision 42720) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Aug 29 05:35:58 2013 Eric Hodel <drbrain@s...> + + * ext/zlib/zlib.c (zstream_run): Fix handling of deflate streams that + need a dictionary but are being decompressed by Zlib::Inflate.inflate + (which has no option to set a dictionary). Now Zlib::NeedDict is + raised instead of crashing. [ruby-trunk - Bug #8829] + * test/zlib/test_zlib.rb (TestZlibInflate): Test for the above. + Thu Aug 29 02:40:45 2013 Aaron Patterson <aaron@t...> * ext/psych/lib/psych/scalar_scanner.rb: invalid floats should be Index: ext/zlib/zlib.c =================================================================== --- ext/zlib/zlib.c (revision 42719) +++ ext/zlib/zlib.c (revision 42720) @@ -1074,11 +1074,13 @@ loop: https://github.com/ruby/ruby/blob/trunk/ext/zlib/zlib.c#L1074 } if (err == Z_NEED_DICT) { VALUE self = (VALUE)z->stream.opaque; - VALUE dicts = rb_ivar_get(self, id_dictionaries); - VALUE dict = rb_hash_aref(dicts, rb_uint2inum(z->stream.adler)); - if (!NIL_P(dict)) { - rb_inflate_set_dictionary(self, dict); - goto loop; + if (self) { + VALUE dicts = rb_ivar_get(self, id_dictionaries); + VALUE dict = rb_hash_aref(dicts, rb_uint2inum(z->stream.adler)); + if (!NIL_P(dict)) { + rb_inflate_set_dictionary(self, dict); + goto loop; + } } } raise_zlib_error(err, z->stream.msg); Index: test/zlib/test_zlib.rb =================================================================== --- test/zlib/test_zlib.rb (revision 42719) +++ test/zlib/test_zlib.rb (revision 42720) @@ -232,6 +232,12 @@ if defined? Zlib https://github.com/ruby/ruby/blob/trunk/test/zlib/test_zlib.rb#L232 end class TestZlibInflate < Test::Unit::TestCase + def test_class_inflate_dictionary + assert_raises(Zlib::NeedDict) do + Zlib::Inflate.inflate([0x08,0x3C,0x0,0x0,0x0,0x0].pack("c*")) + end + end + def test_initialize assert_raise(Zlib::StreamError) { Zlib::Inflate.new(-1) } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/