You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2011/08/02 12:55:48 UTC
svn commit: r1153093 - in /thrift/trunk/lib/rb: ext/memory_buffer.c
lib/thrift/transport/memory_buffer_transport.rb
Author: roger
Date: Tue Aug 2 10:55:47 2011
New Revision: 1153093
URL: http://svn.apache.org/viewvc?rev=1153093&view=rev
Log:
THRIFT-1252 Segfault in Ruby deserializer
Patch: Ilya Maykov
Modified:
thrift/trunk/lib/rb/ext/memory_buffer.c
thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb
Modified: thrift/trunk/lib/rb/ext/memory_buffer.c
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/ext/memory_buffer.c?rev=1153093&r1=1153092&r2=1153093&view=diff
==============================================================================
--- thrift/trunk/lib/rb/ext/memory_buffer.c (original)
+++ thrift/trunk/lib/rb/ext/memory_buffer.c Tue Aug 2 10:55:47 2011
@@ -58,12 +58,12 @@ VALUE rb_thrift_memory_buffer_read(VALUE
rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
index = 0;
}
+ rb_ivar_set(self, index_ivar_id, INT2FIX(index));
if (RSTRING_LEN(data) < length) {
rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
}
- rb_ivar_set(self, index_ivar_id, INT2FIX(index));
return data;
}
@@ -76,12 +76,13 @@ VALUE rb_thrift_memory_buffer_read_byte(
rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
}
char byte = RSTRING_PTR(buf)[index++];
- rb_ivar_set(self, index_ivar_id, INT2FIX(index));
if (index >= GARBAGE_BUFFER_SIZE) {
rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
index = 0;
}
+ rb_ivar_set(self, index_ivar_id, INT2FIX(index));
+
int result = (int) byte;
return INT2FIX(result);
}
@@ -98,12 +99,12 @@ VALUE rb_thrift_memory_buffer_read_into_
rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
}
char byte = RSTRING_PTR(buf)[index++];
- rb_ivar_set(self, index_ivar_id, INT2FIX(index));
if (index >= GARBAGE_BUFFER_SIZE) {
rb_ivar_set(self, buf_ivar_id, rb_funcall(buf, slice_method_id, 2, INT2FIX(index), INT2FIX(RSTRING_LEN(buf) - 1)));
index = 0;
}
+ rb_ivar_set(self, index_ivar_id, INT2FIX(index));
if (i >= RSTRING_LEN(buffer_value)) {
rb_raise(rb_eIndexError, "index %d out of string", i);
Modified: thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb
URL: http://svn.apache.org/viewvc/thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb?rev=1153093&r1=1153092&r2=1153093&view=diff
==============================================================================
--- thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb (original)
+++ thrift/trunk/lib/rb/lib/thrift/transport/memory_buffer_transport.rb Tue Aug 2 10:55:47 2011
@@ -92,6 +92,10 @@ module Thrift
@index += 1
i += 1
end
+ if @index >= GARBAGE_BUFFER_SIZE
+ @buf = @buf.slice(@index..-1)
+ @index = 0
+ end
i
end