Copilot commented on code in PR #3450:
URL: https://github.com/apache/brpc/pull/3450#discussion_r3788760263


##########
src/mcpack2pb/parser.cpp:
##########
@@ -577,6 +577,13 @@ double UnparsedValue::as_double(const char* var) {
 }
 
 void UnparsedValue::as_string(std::string* out, const char* var) {
+    if (_size < 1) {
+        // A string field must contain at least the trailing '\0'.
+        // Reject _size == 0 here, otherwise `_size - 1' underflows and
+        // resize() throws an uncaught exception.
+        _stream->set_bad();
+        return;
+    }
     out->resize(_size - 1);

Review Comment:
   When rejecting `_size == 0`, `as_string` sets the stream bad but leaves 
`*out` unchanged. Callers that reuse the same `std::string` (e.g. when 
encountering duplicate fields) may keep a previously parsed value and 
accidentally treat the request as valid even though the stream is bad. Clear 
the output on this error path so the caller deterministically gets an empty 
string.



-- 
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]

Reply via email to