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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]