Skip to content

fix: reject malformed inner-batch message lengths - #11488

Open
huier5635-cmd wants to merge 1 commit into
apache:developfrom
huier5635-cmd:fix/innerbatch-length-validation
Open

huier5635-cmd wants to merge 1 commit into
apache:developfrom
huier5635-cmd:fix/innerbatch-length-validation

Conversation

@huier5635-cmd

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

No existing issue is linked; the regression tests below reproduce the defect against develop.

Brief Description

MessageDecoder.countInnerMsgNum advances the buffer by the encoded record size. A zero size leaves the position unchanged and the loop never terminates. The broker calls this method when processing an inner batch for a BatchCQ topic.

Validate that a size field is present, the record includes the 22-byte encoded header, and the record fits within the remaining buffer before advancing and counting it. Return MESSAGE_ILLEGAL for malformed or empty inner batches before invoking storage.

Regression tests cover stalled and invalid record lengths, a malformed following record, valid encoded batches with direct/read-only buffers and nonzero positions, and the actual broker rejection/storage paths. Valid batches retain their body, message count, flags, and successful response.

How Did You Test This Change?

Validated against Apache commit 38a7ca0d23a3e2d4339f9a2bf6e78cf541eed9e3, including recursive submodules, on Ubuntu 24.04 with Corretto JDK 8 and Maven 3.10.0. Maven's default Checkstyle and JaCoCo configuration remained enabled.

  • Original broker reactor build/install passed: mvn -B -ntp -pl broker -am -DskipTests install.
  • With only the new tests applied, the zero-length decoder and broker tests timed out as expected; both valid-message controls passed against the original code.
  • With the complete fix applied, mvn -B -ntp -pl broker -am -Dtest=MessageDecoderTest,SendMessageProcessorTest -Dsurefire.failIfNoSpecifiedTests=false test passed all 30 tests in the two related classes, with no skips.
  • mvn -B -ntp -pl common test passed all 271 tests, with no skips.
  • Strict patch application, git diff --check, and verification of the four final source-file hashes passed.

Reproducible validation run and raw XML/log artifact. The validation workflow checks out and tests the Apache sources; it is not part of this PR. The full broker suite and a live broker cluster were not run.

Validate record boundaries before advancing the decoder, return MESSAGE_ILLEGAL
for invalid or empty inner batches, and cover stalled and valid broker paths.

Signed-off-by: huier <huier5635@gmail.com>
@codecov-commenter

codecov-commenter commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.79%. Comparing base (38a7ca0) to head (e29aee6).
⚠️ Report is 6 commits behind head on develop.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #11488      +/-   ##
=============================================
+ Coverage      49.76%   49.79%   +0.03%     
- Complexity     14381    14389       +8     
=============================================
  Files           1391     1391              
  Lines         103350   103361      +11     
  Branches       13518    13521       +3     
=============================================
+ Hits           51428    51469      +41     
+ Misses         45711    45672      -39     
- Partials        6211     6220       +9     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants