You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "chennaji9 (via GitHub)" <gi...@apache.org> on 2026/09/30 09:56:28 UTC

[I] [Bug] RpcClientUtils.encodeBody overwrites the caller's ByteBuffer mark [rocketmq]

chennaji9 opened a new issue, #11283:
URL: https://github.com/apache/rocketmq/issues/11283

   ### Description
   
   `RpcClientUtils.encodeBody` in the remoting module mutates buffer state it does not own:
   
   ```java
   } else if (body instanceof ByteBuffer) {
       ByteBuffer buffer = (ByteBuffer)body;
       buffer.mark();
       byte[] data = new byte[buffer.remaining()];
       buffer.get(data);
       buffer.reset();
       return data;
   }
   ```
   
   The method restores the buffer's `position` (via mark/reset) but **overwrites whatever mark the caller had previously set**. A caller that did `buffer.mark()` at position 1, advanced to position 3, then passed the buffer through `encodeBody` gets back a buffer whose mark is now 3; a later `buffer.reset()` jumps to 3 instead of 1. Encoding a body therefore has an observable side effect on the caller's buffer beyond reading it.
   
   Additionally, when the caller's `position`/`mark`/`limit` are what they are, the encode itself must only read the remaining bytes — which `duplicate()` achieves without touching the original buffer's position, limit or mark at all.
   
   ### Expected behavior
   
   `encodeBody` should be side-effect free on the passed-in `ByteBuffer`: read the remaining bytes from `buffer.duplicate()` and leave the original buffer's position, limit and mark untouched.


-- 
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: commits-unsubscribe@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] RpcClientUtils.encodeBody overwrites the caller's ByteBuffer mark [rocketmq]

Posted by "RongtongJin (via GitHub)" <gi...@apache.org>.
RongtongJin closed issue #11283: [Bug] RpcClientUtils.encodeBody overwrites the caller's ByteBuffer mark
URL: https://github.com/apache/rocketmq/issues/11283


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org