Copilot commented on code in PR #3576:
URL: https://github.com/apache/brpc/pull/3576#discussion_r4151948091
##########
src/mcpack2pb/parser.cpp:
##########
@@ -586,9 +620,7 @@ void UnparsedValue::as_string(std::string* out, const char*
var) {
_stream->set_bad();
return;
}
- out->resize(_size - 1);
- if (_stream->cutn(&(*out)[0], _size - 1) != _size - 1) {
- CHECK(false) << "Not enough data for " << var;
+ if (!cut_bytes_to_string(_stream, out, _size - 1, var)) {
return;
}
_stream->popn(1);
Review Comment:
A string truncated by exactly its terminator is not marked bad here:
`cut_bytes_to_string()` successfully consumes the declared data bytes, then the
unchecked `popn(1)` returns 0 while `stream.good()` remains true. This leaves
`as_string()` reporting success for malformed input, contrary to the new
truncation behavior. Check the terminator consumption and clear the output/mark
the stream bad on a short read.
--
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]