Skip to content

fix(broker): reject timer delays that overflow the absolute delivery time - #10965

Open
GerardGao wants to merge 2 commits into
apache:developfrom
GerardGao:fix/issue-10872-timer-delay-overflow
Open

fix(broker): reject timer delays that overflow the absolute delivery time#10965
GerardGao wants to merge 2 commits into
apache:developfrom
GerardGao:fix/issue-10872-timer-delay-overflow

Conversation

@GerardGao

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Brief Description

HookUtils.transformTimerMessage converted relative timer delays (TIMER_DELAY_SEC / TIMER_DELAY_MS) into an absolute delivery timestamp with unchecked long multiplication and addition. A very large delay such as Long.MAX_VALUE overflowed into a past timestamp, bypassed the future-delivery validation, and took the immediate-message path instead of being rejected.

This change uses Math.multiplyExact / Math.addExact for the conversion. The existing catch (Exception) in the method turns the resulting ArithmeticException into PutMessageStatus.WHEEL_TIMER_MSG_ILLEGAL, so an unrepresentable delay is now rejected. It also snapshots System.currentTimeMillis() once per invocation so the conversion and the future-delivery check share the same time base.

How Did You Test This Change?

  • New HookUtilsTimerOverflowTest with three cases:
    • TIMER_DELAY_SEC = Long.MAX_VALUE is rejected with WHEEL_TIMER_MSG_ILLEGAL;
    • TIMER_DELAY_MS = Long.MAX_VALUE is rejected with WHEEL_TIMER_MSG_ILLEGAL;
    • a delay that does not overflow but exceeds timerMaxDelaySec is still rejected (covers the future-delivery branch).
  • On the unfixed code the overflow cases fail (the message takes the immediate path); after the fix all three pass.
  • mvn -pl broker -am test: 763 tests, 0 failures (the single unrelated BrokerOuterAPITest error is a JDK 17 module-access issue in the test constructor, absent under the project's CI JDK 8).
  • New patch lines are fully covered by the added tests.

…time

transformTimerMessage converted relative timer delays with unchecked long multiplication and addition, so a very large delay overflowed into a past timestamp, bypassed the future-delay validation, and took the immediate-message path. Use Math.multiplyExact/Math.addExact so overflow returns WHEEL_TIMER_MSG_ILLEGAL.

Fixes apache#10872

@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

Fixes an integer overflow in HookUtils.transformTimerMessage where large relative timer delays (e.g. Long.MAX_VALUE) could wrap around to a past timestamp and bypass validation. The fix uses Math.multiplyExact/Math.addExact to detect overflow, and the existing catch (Exception) converts the ArithmeticException to WHEEL_TIMER_MSG_ILLEGAL. Also snapshots currentTimeMillis() once per invocation for a consistent time base.

Clean, well-scoped fix with good regression test coverage. LGTM.


Automated review by github-manager-bot

@codecov-commenter

codecov-commenter commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.51%. Comparing base (484b7b8) to head (f2427de).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
...ava/org/apache/rocketmq/broker/util/HookUtils.java 75.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10965      +/-   ##
=============================================
- Coverage      48.57%   48.51%   -0.06%     
+ Complexity     13667    13657      -10     
=============================================
  Files           1381     1381              
  Lines         101475   101480       +5     
  Branches       13189    13190       +1     
=============================================
- Hits           49293    49238      -55     
- Misses         46183    46214      +31     
- Partials        5999     6028      +29     

☔ 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.

Cover the remaining transformTimerMessage branches so the exact-math
overflow checks and the millisecond success path are exercised:

- Long.MAX_VALUE / 1000 overflows addExact after multiplyExact succeeds.
- A valid PROPERTY_TIMER_DELAY_MS rewrites the message to the wheel-timer
  topic with PROPERTY_TIMER_OUT_MS set.

Split the nested exact-math expression in HookUtils so each overflow
source is independently testable and reported.
@GerardGao

Copy link
Copy Markdown
Author

Updated in f2427de to address the codecov feedback: added testTimerDelaySecAddExactOverflowRejected (addExact overflow after multiplyExact succeeds) and testTimerDelayMsSuccessPath, and split the nested exact-math expression in HookUtils so each overflow source is independently testable. Local check: mvn -pl broker -Dtest=HookUtilsTimerOverflowTest test → 5 tests, 0 failures, and all changed lines are now covered.

Note: the new commit's workflow runs are waiting for maintainer approval (action_required), so CI hasn't run yet on f2427de.

@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

Re-reviewed after new commit f2427de6 which adds test coverage for the timer delay overflow fix. The production code change in HookUtils.transformTimerMessage correctly uses Math.multiplyExact / Math.addExact to detect overflow, with exceptions caught by the existing error handler returning WHEEL_TIMER_MSG_ILLEGAL. The new tests cover both overflow paths and the success path.

LGTM — clean fix with good test coverage.


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.

[Bug] Overflowing relative timer delays can be treated as immediate

4 participants