fix(broker): reject timer delays that overflow the absolute delivery time - #10965
fix(broker): reject timer delays that overflow the absolute delivery time#10965GerardGao wants to merge 2 commits into
Conversation
…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
left a comment
There was a problem hiding this comment.
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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.
|
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: Note: the new commit's workflow runs are waiting for maintainer approval ( |
RockteMQ-AI
left a comment
There was a problem hiding this comment.
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
Which Issue(s) This PR Fixes
Brief Description
HookUtils.transformTimerMessageconverted relative timer delays (TIMER_DELAY_SEC/TIMER_DELAY_MS) into an absolute delivery timestamp with uncheckedlongmultiplication and addition. A very large delay such asLong.MAX_VALUEoverflowed 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.addExactfor the conversion. The existingcatch (Exception)in the method turns the resultingArithmeticExceptionintoPutMessageStatus.WHEEL_TIMER_MSG_ILLEGAL, so an unrepresentable delay is now rejected. It also snapshotsSystem.currentTimeMillis()once per invocation so the conversion and the future-delivery check share the same time base.How Did You Test This Change?
HookUtilsTimerOverflowTestwith three cases:TIMER_DELAY_SEC = Long.MAX_VALUEis rejected withWHEEL_TIMER_MSG_ILLEGAL;TIMER_DELAY_MS = Long.MAX_VALUEis rejected withWHEEL_TIMER_MSG_ILLEGAL;timerMaxDelaySecis still rejected (covers the future-delivery branch).mvn -pl broker -am test: 763 tests, 0 failures (the single unrelatedBrokerOuterAPITesterror is a JDK 17 module-access issue in the test constructor, absent under the project's CI JDK 8).