Copilot commented on code in PR #3575:
URL: https://github.com/apache/brpc/pull/3575#discussion_r4151897804
##########
src/brpc/policy/mysql/mysql_reply.cpp:
##########
@@ -267,25 +319,37 @@ ParseError MysqlReply::ConsumePartialIOBuf(butil::IOBuf&
buf,
MY_PARSE_CHECK(_data.auth->Parse(buf, arena));
return PARSE_OK;
}
+ // A 0xFE-leading packet is an EOF only when it is short (payload < 9
+ // bytes, per the MySQL protocol); a longer 0xFE-leading packet starts a
+ // length-encoded column count and belongs to the result-set branch below.
+ const bool is_eof_packet =
+ (type == 0xFE) && (_type == MYSQL_RSP_EOF || mysql_uint3korr(p) < 9);
if (type == 0x00 && (is_auth || stmt_type != MYSQL_NEED_PREPARE)) {
_type = MYSQL_RSP_OK;
MY_ALLOC_CHECK(my_alloc_check(arena, 1, _data.ok));
MY_PARSE_CHECK(_data.ok->Parse(buf, arena));
*more_results = _data.ok->status() & MYSQL_SERVER_MORE_RESULTS_EXISTS;
- } else if ((type == 0x00 && stmt_type == MYSQL_NEED_PREPARE) || type ==
MYSQL_RSP_PREPARE_OK) {
+ } else if ((type == 0x00 && stmt_type == MYSQL_NEED_PREPARE) ||
+ _type == MYSQL_RSP_PREPARE_OK) {
_type = MYSQL_RSP_PREPARE_OK;
MY_ALLOC_CHECK(my_alloc_check(arena, 1, _data.prepare_ok));
MY_PARSE_CHECK(_data.prepare_ok->Parse(buf, arena));
} else if (type == 0xFF) {
_type = MYSQL_RSP_ERROR;
MY_ALLOC_CHECK(my_alloc_check(arena, 1, _data.error));
MY_PARSE_CHECK(_data.error->Parse(buf, arena));
- } else if (type == 0xFE) {
+ } else if (is_eof_packet) {
_type = MYSQL_RSP_EOF;
MY_ALLOC_CHECK(my_alloc_check(arena, 1, _data.eof));
MY_PARSE_CHECK(_data.eof->Parse(buf));
*more_results = _data.eof->status() & MYSQL_SERVER_MORE_RESULTS_EXISTS;
- } else if (type >= 0x01 && type <= 0xFA) {
+ } else if (type >= 0x01 && type <= 0xFE) {
+ // Any other leading byte is the length-encoded column count of a
+ // result set, including the multi-byte prefixes 0xFB (251) and
+ // 0xFC (252..65535) and a long 0xFE-leading count. These bytes must
Review Comment:
A bare `0xFB` is the length-encoded NULL marker, not an encoding of column
count 251. This new branch routes it into `ResultSetHeader::Parse`, where
`parse_encode_length` returns success with value 0; because zero is not
rejected, a `0xFB` header followed by two EOF packets is accepted as a
zero-column result set. Exclude `0xFB` from fresh result-set dispatch (251 is
correctly encoded as `FC FB 00`).
--
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]