Copilot commented on code in PR #3641:
URL: https://github.com/apache/thrift/pull/3641#discussion_r3611141151


##########
lib/rb/ext/memory_buffer.c:
##########
@@ -126,6 +126,11 @@ VALUE rb_thrift_memory_buffer_read_into_buffer(VALUE self, 
VALUE buffer_value, V
   int index;
   VALUE buf = GET_BUF(self);
 
+  if (size > 0) {
+    Check_Type(buffer_value, T_STRING);
+    rb_str_modify(buffer_value);
+  }

Review Comment:
   The native implementation can consume one byte of input before verifying the 
destination buffer is large enough: `index++` happens before the `i >= 
RSTRING_LEN(buffer_value)` check. If the destination is too short, an 
IndexError will be raised after advancing `@index`, which can drop bytes and 
diverges from the pure-Ruby implementation (which raises before consuming). 
Reorder the loop to check destination bounds before incrementing index and 
writing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to