Skip to content

[ISSUE #S5] Clamp negative maxNum in IndexService.queryOffset - #11099

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/index-service-query-offset-negative-maxnum
Open

[ISSUE #S5] Clamp negative maxNum in IndexService.queryOffset#11099
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/index-service-query-offset-negative-maxnum

Conversation

@zjncs

@zjncs zjncs commented Sep 9, 2026

Copy link
Copy Markdown

Motivation

maxNum reaches IndexService.queryOffset straight from QueryMessageRequestHeader, where the field is only annotated @CFNotNull — no range validation. A negative value therefore survives the existing

maxNum = Math.min(maxNum, this.defaultMessageStore.getMessageStoreConfig().getMaxMsgsNumBatch());
List<Long> phyOffsets = new ArrayList<>(maxNum);

cap (min of a negative and a positive is still negative) and new ArrayList<>(maxNum) throws IllegalArgumentException: Illegal Capacity: -1 before the try block, so it propagates uncaught through DefaultMessageStore.queryMessage back to the request processor, answering the client with an opaque SYSTEM_ERROR.

Modifications

  • Clamp maxNum to a minimum of 0 before the cap: Math.min(Math.max(maxNum, 0), maxMsgsNumBatch). A negative request now simply returns an empty QueryOffsetResult, consistent with maxNum == 0.

Verification

Fail-before (new test on unpatched code):

IndexServiceTest.testQueryOffsetWithNegativeMaxNum:87 » IllegalArgument Illegal Capacity: -1

Pass-after — full IndexServiceTest (5 existing + 1 new):

mvn -pl store test -Dtest='IndexServiceTest'
Tests run: 6, Failures: 0, Errors: 0, Skipped: 0

maxNum reaches queryOffset straight from QueryMessageRequestHeader, where
it is only checked for null. A negative value survives the
Math.min(maxNum, maxMsgsNumBatch) cap and makes new ArrayList<>(maxNum)
throw IllegalArgumentException: Illegal Capacity, which propagates to the
caller as an opaque failure instead of an empty result. Clamp it to 0.

Signed-off-by: zjncs <18910855655@163.com>
Copilot AI lite review requested due to automatic review settings September 9, 2026 10:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-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.

Summary

Clamps negative maxNum to 0 before using it in ArrayList allocation — prevents IllegalArgumentException from propagating as an opaque SYSTEM_ERROR. Clean, minimal fix with a regression test.

LGTM.


Automated review by github-manager-bot

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