Permalink
Browse files

build strings and binaries on the heap and test to make sure it works

  • Loading branch information...
mojombo committed Oct 28, 2009
1 parent 5461460 commit fa40ec72dc3bef1e6fd899280e1b4d2bb973465d
Showing with 9 additions and 2 deletions.
  1. +4 −2 ext/bert/c/decode.c
  2. +5 −0 test/decoder_test.rb
View
@@ -228,10 +228,12 @@ VALUE read_bin(unsigned char **pData) {
unsigned int length = read_4(pData);
- unsigned char buf[length + 1];
+ unsigned char* buf = malloc(length + 1);
read_string_raw(buf, pData, length);
+ VALUE rStr = rb_str_new((char *) buf, length);
+ free(buf);
- return rb_str_new((char *) buf, length);
+ return rStr;
}
VALUE read_string(unsigned char **pData) {
View
@@ -72,5 +72,10 @@ class DecoderTest < Test::Unit::TestCase
after = [1, 2.0, [:foo, 'bar']]
assert_equal after, BERT::Decoder.decode(bert)
end
+
+ should "handle massive binaries" do
+ bert = [131,109,0,128,0,0].pack('c*') + ('a' * (8 * 1024 * 1024))
+ assert_equal (8 * 1024 * 1024), BERT::Decoder.decode(bert).size
+ end
end
end

0 comments on commit fa40ec7

Please sign in to comment.