Permalink
Browse files

check for unexpected end of structures

  • Loading branch information...
1 parent 4a7bce2 commit 7cb85557b9ba5ba2630a356bc7d09faf49ddf330 @naquad committed Jan 22, 2011
Showing with 3 additions and 0 deletions.
  1. +2 −0 ext/bencode_ext/bencode.c
  2. +1 −0 test/test_bencode_ext.rb
@@ -157,6 +157,8 @@ static VALUE decode(VALUE self, VALUE encoded){
if(len)
rb_raise(DecodeError, "String has garbage on the end (starts at %d).", rlen - len);
+ else if(!NIL_P(current_container))
+ rb_raise(DecodeError, "Unpexpected end of %s.", BUILTIN_TYPE(current_container) == T_HASH ? "dictionary" : "list");
return ret;
}
View
@@ -27,6 +27,7 @@ def test_decoding
assert_raises(BEncode::DecodeError) {'33:unpexpected_end'.bdecode }
assert_raises(BEncode::DecodeError) { 'i1x'.bdecode }
assert_raises(BEncode::DecodeError) { '2:asd'.bdecode }
+ assert_raises(BEncode::DecodeError) { 'd'.bdecode }
assert_raises(ArgumentError) { BEncode.max_depth = 1.1 }
assert_raises(ArgumentError) { BEncode.max_depth = -5 }
assert_raises(BEncode::DecodeError) do

0 comments on commit 7cb8555

Please sign in to comment.