Copilot commented on code in PR #3392:
URL: https://github.com/apache/brpc/pull/3392#discussion_r3618835421
##########
src/brpc/memcache.cpp:
##########
@@ -503,8 +503,12 @@ bool MemcacheResponse::PopStore(uint8_t command, uint64_t*
cas_value) {
- (int)header.key_length;
if (header.status != (uint16_t)STATUS_SUCCESS) {
_buf.pop_front(sizeof(header) + header.extras_length +
header.key_length);
- _err.clear();
- _buf.cutn(&_err, value_size);
+ if (value_size < 0) {
+ butil::string_printf(&_err, "value_size=%d is negative",
value_size);
+ } else {
Review Comment:
When `value_size < 0` (i.e., `extras_length + key_length >
total_body_length`), this code has already executed
`_buf.pop_front(sizeof(header) + header.extras_length + header.key_length)`,
which pops past the declared message boundary and consumes bytes from the
following pipelined response. This can still desync the connection even though
the `cutn()` underflow is avoided. Consider checking `value_size < 0` before
popping `extras_length + key_length`, and in the malformed case discard only
`sizeof(header) + header.total_body_length` (the declared message size).
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]