Repository navigation
server: harden parseBinaryParams against malformed length-encoded values - #68917
ti-chi-bot[bot] merged 4 commits into
Conversation
|
@expxiaoli I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details. ⏳ This process typically takes 10-30 minutes depending on the complexity of the changes. ℹ️ Learn more details on Pantheon AI. |
|
Hi @expxiaoli. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds error reporting for truncated length-encoded integers, centralizes safe extraction of length-encoded parameter payloads, refactors binary parameter parsing to use the helper, updates handshake parsing to check length-encoding errors, and adds tests for malformed/truncated headers. ChangesLength-encoded parameter parsing and malformed packet handling
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/server/conn_stmt_params_test.go (1)
285-317: ⚡ Quick winAdd a plain short-payload regression case.
This covers the truncated-header path and the huge-length overflow path, but it doesn't directly exercise the Line 51 remaining-bytes guard in
pkg/server/conn_stmt_params.go. A case with a valid header and too few payload bytes would lock in the common truncation path this PR is hardening.🧪 Minimal addition
{ name: "truncated length-encoded uint64 header", paramValues: []byte{0xfe}, }, + { + name: "declared length exceeds remaining payload", + paramValues: []byte{0x03, 'a', 'b'}, + }, { name: "overflowing length-encoded uint64", // length = 1<<63, which previously could slip past `pos + int(length)` checks and panic on slicing. paramValues: []byte{0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80}, },🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/server/conn_stmt_params_test.go` around lines 285 - 317, Add a regression case to TestParseExecArgsMalformedLengthEncodedParam that exercises the "valid header but too few payload bytes" path: append a test entry whose paramValues contains a well-formed length-encoded header (e.g., 0xFC followed by a 2-byte little-endian length > actual payload) but then provides fewer payload bytes than that length so decodeAndParse triggers the remaining-bytes guard in conn_stmt_params.go; ensure the test still asserts mysql.ErrMalformPacket via the same decodeAndParse call.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/server/conn_stmt_params_test.go`:
- Around line 285-317: Add a regression case to
TestParseExecArgsMalformedLengthEncodedParam that exercises the "valid header
but too few payload bytes" path: append a test entry whose paramValues contains
a well-formed length-encoded header (e.g., 0xFC followed by a 2-byte
little-endian length > actual payload) but then provides fewer payload bytes
than that length so decodeAndParse triggers the remaining-bytes guard in
conn_stmt_params.go; ensure the test still asserts mysql.ErrMalformPacket via
the same decodeAndParse call.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e1c50dd9-7738-47a1-9c20-48cf40848ad0
📒 Files selected for processing (2)
pkg/server/conn_stmt_params.gopkg/server/conn_stmt_params_test.go
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #68917 +/- ##
================================================
- Coverage 76.3186% 75.0901% -1.2285%
================================================
Files 2041 2027 -14
Lines 562849 569350 +6501
================================================
- Hits 429559 427526 -2033
- Misses 132377 141711 +9334
+ Partials 913 113 -800
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/retest |
|
@wuhuizuo: PRs from untrusted users cannot be marked as trusted with DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lance6716, wjhuang2016, YangKeao The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest-required |
|
@expxiaoli: PRs from untrusted users cannot be marked as trusted with DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/retest-required |
|
@expxiaoli: PRs from untrusted users cannot be marked as trusted with DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/retest |
|
@expxiaoli: PRs from untrusted users cannot be marked as trusted with DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/retest |
|
/ok-to-test |
80dcc68 to
e56167d
Compare
What problem does this PR solve?
Issue Number: close #67486
Problem Summary:
This PR supersedes #67542. I do not have write access to the original contributor branch, so I am carrying the same fix forward on a branch I can maintain.
Malformed length-encoded parameter payloads in
COM_STMT_EXECUTEmay panic inparseBinaryParams. Large or truncated values should be rejected as malformed packets instead of reaching unsafe slicing logic.What changed and how does it work?
This PR keeps the original hardening change and continues from it:
uint64-safe bounds before converting tointand slicing.Check List
Tests
Side effects
Documentation
Release note
Summary by CodeRabbit
Bug Fixes
Refactor
Tests