erlectricity 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ == 1.1.1 / 2009-10-28
2
+ * Bug Fixes
3
+ * Fix bignum encoding
4
+ * Prevent stack overflow for massive binaries in c decoder
5
+ * Optimize strings in c decoder
6
+
1
7
  == 1.1.0 / 2009-10-08
2
8
  * Minor Improvements
3
9
  * Implement Bignum encoding
@@ -1,4 +1,4 @@
1
1
  ---
2
- :major: 1
3
2
  :minor: 1
4
- :patch: 0
3
+ :patch: 1
4
+ :major: 1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{erlectricity}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Scott Fleckenstein", "Tom Preston-Werner"]
12
- s.date = %q{2009-10-08}
12
+ s.date = %q{2009-10-28}
13
13
  s.email = %q{tom@mojombo.com}
14
14
  s.extensions = ["ext/extconf.rb"]
15
15
  s.extra_rdoc_files = [
@@ -97,7 +97,7 @@ VALUE read_large_tuple(unsigned char **pData) {
97
97
  rb_raise(rb_eStandardError, "Invalid Type, not a large tuple");
98
98
  }
99
99
 
100
- int arity = read_4(pData);
100
+ unsigned int arity = read_4(pData);
101
101
 
102
102
  VALUE array = rb_ary_new2(arity);
103
103
 
@@ -114,7 +114,7 @@ VALUE read_list(unsigned char **pData) {
114
114
  rb_raise(rb_eStandardError, "Invalid Type, not an erlang list");
115
115
  }
116
116
 
117
- int size = read_4(pData);
117
+ unsigned int size = read_4(pData);
118
118
 
119
119
  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
120
120
  VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(size));
@@ -131,7 +131,7 @@ VALUE read_list(unsigned char **pData) {
131
131
 
132
132
  // primitives
133
133
 
134
- void read_string_raw(unsigned char *dest, unsigned char **pData, int length) {
134
+ void read_string_raw(unsigned char *dest, unsigned char **pData, unsigned int length) {
135
135
  memcpy((char *) dest, (char *) *pData, length);
136
136
  *(dest + length) = (unsigned char) 0;
137
137
  *pData += length;
@@ -142,12 +142,12 @@ VALUE read_bin(unsigned char **pData) {
142
142
  rb_raise(rb_eStandardError, "Invalid Type, not an erlang binary");
143
143
  }
144
144
 
145
- int length = read_4(pData);
145
+ unsigned int length = read_4(pData);
146
146
 
147
- unsigned char buf[length + 1];
148
- read_string_raw(buf, pData, length);
147
+ VALUE rStr = rb_str_new((char *) *pData, length);
148
+ *pData += length;
149
149
 
150
- return rb_str_new((char *) buf, length);
150
+ return rStr;
151
151
  }
152
152
 
153
153
  VALUE read_string(unsigned char **pData) {
@@ -156,16 +156,13 @@ VALUE read_string(unsigned char **pData) {
156
156
  }
157
157
 
158
158
  int length = read_2(pData);
159
-
160
- unsigned char buf[length + 1];
161
- read_string_raw(buf, pData, length);
162
-
163
159
  VALUE newref_class = rb_const_get(mErlectricity, rb_intern("List"));
164
160
  VALUE array = rb_funcall(newref_class, rb_intern("new"), 1, INT2NUM(length));
165
161
 
166
162
  int i = 0;
167
163
  for(i; i < length; ++i) {
168
- rb_ary_store(array, i, INT2NUM(*(buf + i)));
164
+ rb_ary_store(array, i, INT2NUM(**pData));
165
+ *pData += 1;
169
166
  }
170
167
 
171
168
  return array;
@@ -101,10 +101,10 @@ module Erlectricity
101
101
  def write_bignum_guts(num)
102
102
  write_1 (num >= 0 ? 0 : 1)
103
103
  num = num.abs
104
- i = 0
105
- while (rem = (num >> i * 8) % (256)) != 0
104
+ while num != 0
105
+ rem = num % 256
106
106
  write_1 rem
107
- i += 1
107
+ num = num >> 8
108
108
  end
109
109
  end
110
110
 
@@ -127,6 +127,11 @@ context "When unpacking from a binary stream" do
127
127
  get("f").should == :f
128
128
  end
129
129
 
130
+ specify "massive binaries should not overflow the stack" do
131
+ bin = [131,109,0,128,0,0].pack('c*') + ('a' * (8 * 1024 * 1024))
132
+ assert_equal (8 * 1024 * 1024), Erlectricity::Decoder.decode(bin).size
133
+ end
134
+
130
135
  specify "a good thing should be awesome" do
131
136
  get(%Q-[{options,{struct,[{test,<<"I'm chargin' mah lazer">>}]}},{passage,<<"Why doesn't this work?">>}]-).should ==
132
137
  [[:options, [:struct, [[:test, "I'm chargin' mah lazer"]]]], [:passage, "Why doesn't this work?"]]
@@ -36,6 +36,7 @@ context "When packing to a binary stream" do
36
36
  write_any(-(1 << 27)).should == get_erl_with_magic("#{-(1 << 27)}")
37
37
 
38
38
  # #SMALL_BIGNUMS
39
+ get{@encoder.write_fixnum(10_000_000_000_000_000_000)}.should == get_erl("10000000000000000000")
39
40
  get{@encoder.write_fixnum(1254976067)}.should == get_erl("1254976067")
40
41
  get{@encoder.write_fixnum(-1254976067)}.should == get_erl("-1254976067")
41
42
  # get{@encoder.write_fixnum((1 << word_length))}.should == get_erl("#{(1 << word_length)}")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erlectricity
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-08 00:00:00 -07:00
13
+ date: 2009-10-28 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16