Author: bryanduxbury
Date: Fri Jun 29 00:21:19 2012
New Revision: 1355198
URL: http://svn.apache.org/viewvc?rev=1355198&view=rev
Log:
THRIFT-1632. rb: ruby: data corruption in thrift_native implementation of
MemoryBufferTransport
This patch fixes a subtle bug whereby the read buffer was being resized but the
method continued to read from the original, unresized buffer but at the wrong
location.
Modified:
thrift/trunk/lib/rb/ext/memory_buffer.c
Modified: thrift/trunk/lib/rb/ext/memory_buffer.c
URL:
http://svn.apache.org/viewvc/thrift/trunk/lib/rb/ext/memory_buffer.c?rev=1355198&r1=1355197&r2=1355198&view=diff
==============================================================================
--- thrift/trunk/lib/rb/ext/memory_buffer.c (original)
+++ thrift/trunk/lib/rb/ext/memory_buffer.c Fri Jun 29 00:21:19 2012
@@ -93,25 +93,26 @@ VALUE rb_thrift_memory_buffer_read_into_
int index;
VALUE buf = GET_BUF(self);
+ index = FIX2INT(rb_ivar_get(self, index_ivar_id));
while (i < size) {
- index = FIX2INT(rb_ivar_get(self, index_ivar_id));
if (index >= RSTRING_LEN(buf)) {
rb_raise(rb_eEOFError, "Not enough bytes remain in memory buffer");
}
char byte = RSTRING_PTR(buf)[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);
}
((char*)RSTRING_PTR(buffer_value))[i] = byte;
i++;
}
+
+ 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));
+
return INT2FIX(i);
}