ubeddulla commented on code in PR #3402:
URL: https://github.com/apache/brpc/pull/3402#discussion_r3671501027
##########
src/brpc/couchbase.cpp:
##########
@@ -1506,10 +1506,14 @@ bool
CouchbaseOperations::CouchbaseResponse::popCollectionId(
if (header.status != 0) {
// handle error case
- _buf.pop_front(sizeof(header) + header.extras_length + header.key_length);
// Possibly read error message from value if present
- size_t value_size =
- header.total_body_length - header.extras_length - header.key_length;
+ const int value_size = (int)header.total_body_length -
+ (int)header.extras_length - (int)header.key_length;
+ if (value_size < 0) {
+ butil::string_printf(&_err, "value_size=%d is negative", value_size);
+ return false;
+ }
Review Comment:
Good point. Switched all three computations to int64_t with static_cast, so
a body larger than INT_MAX can't wrap to a false negative anymore. cutn still
gets a size_t and value_size is guaranteed >= 0 by the time we reach it. Pushed.
--
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]