Skip to content

Reject empty MySQL response packets - #3536

Merged
wasphin merged 1 commit into
apache:masterfrom
wasphin:fix-mysql-empty-packet
Sep 12, 2026
Merged

Reject empty MySQL response packets#3536
wasphin merged 1 commit into
apache:masterfrom
wasphin:fix-mysql-empty-packet

Conversation

@wasphin

@wasphin wasphin commented Sep 11, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number:

Problem Summary:

The MySQL response parser reads the response type byte without first
rejecting packets whose declared payload length is zero. When another packet
follows, the parser may treat that packet's first byte as the empty packet's
type.

What is changed and the side effects?

Changed:

  • Reject zero-length MySQL response packets before reading their type.
  • Apply the same validation after a fast-auth marker.
  • Cover standalone and followed-by-another-packet cases.

Side effects:

  • Performance effects: One payload-length check while determining a response
    type.
  • Breaking backward compatibility: Invalid zero-length response packets are
    rejected instead of being interpreted using following bytes.

Check List:

Validate packet payload lengths before reading the response type byte.
This prevents an empty packet from borrowing the first byte of a
following packet during response parsing.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues were identified, and regression coverage was added.

Pull request overview

This PR hardens MySQL response parsing by rejecting zero-length packets before reading their response type.

Changes:

  • Validates empty packets, including after fast-auth markers.
  • Adds regression tests for standalone, trailing, and fast-auth cases.
File summaries
File Description
test/brpc_mysql_reply_parse_unittest.cpp Tests malformed empty-packet scenarios.
src/brpc/policy/mysql/mysql_reply.cpp Rejects zero-length packets during response parsing.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@wwbmmm

wwbmmm commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

LGTM

@wasphin

wasphin commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

The two flaky unit tests are not related to this change, and I will fix them separately.

@wasphin
wasphin merged commit 5934fc0 into apache:master Sep 12, 2026
44 of 46 checks passed
@wasphin
wasphin deleted the fix-mysql-empty-packet branch September 12, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants