dragonknightk opened a new pull request, #11567:
URL: https://github.com/apache/rocketmq/pull/11567
### Which Issue(s) This PR Fixes
- Fixes #10871
### Brief Description
`StatisticsBrief` previously checked only that the metadata array is
non-empty and each row has two elements. Malformed bucket configurations were
accepted at construction time and later caused division by zero in slot index
lookup, out-of-bounds or cross-bucket writes during sampling, corrupted
percentile bounds, or array-size integer overflow.
Bucket validation now enforces these invariants, treating the first bucket
as starting at 0 and reserving one trailing overflow slot in the total slot
count:
- Reject a non-positive first boundary and a non-increasing later range
maximum, including a later Long.MIN_VALUE that underflows the width subtraction
to a large positive value, because non-monotonic ranges break width
calculations.
- Reject a non-positive slot count and a slot count larger than the range
width, because integer division of the width by the slot count would truncate
to zero and throw ArithmeticException during sampling. The non-positive slot
count check is evaluated first so the later remainder test cannot divide by
zero.
- Reject a slot count that does not evenly divide the range width. Integer
division otherwise truncates the slot step, so {{10, 6}} then sample(9) throws
ArrayIndexOutOfBoundsException and {{10, 3}, {20, 10}} then sample(9) writes
into the next bucket. Production metadata in BrokerStatsManager is evenly
divisible and remains accepted.
- Reject a slot count that would make the running total exceed
Integer.MAX_VALUE before accumulation, because the array-size helper casts the
total to int, and subtracting from Integer.MAX_VALUE avoids long overflow when
a slot count approaches Long.MAX_VALUE.
### How Did You Test This Change?
Unit tests in `StatisticsBriefTest` cover the rejected and accepted
contracts.
The rejected cases include null or malformed shapes, a zero or negative slot
count, non-increasing or non-positive range bounds (including a later
Long.MIN_VALUE that underflows the width subtraction), a slot count larger than
the range width, a slot count that does not evenly divide the range width, and
single- or multi-bucket totals that exceed Integer.MAX_VALUE (including
Long.MAX_VALUE). The accepted path uses production-like metadata in which each
slot count evenly divides its range width, including the first-bucket boundary
where the slot count equals the range maximum, and checks sampling, percentile
calculation, and reset.
## AI Disclosure
Human-led contribution. Grok Bot, working for dragonknightk, assisted with
this change, including the code, tests, and description. All submitted content
was reviewed by a human before submission.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]