The GitHub Actions job "Run Integration Tests" on 
rocketmq.git/fix-statistics-brief-meta-10871 has failed.
Run started by GitHub user dragonknightk (triggered by ShannonDing).

Head commit for run:
3e925c08701123686c7ac6e88aadb47ae33574f4 / dragonknightk 
<[email protected]>
[ISSUE 10871] fix(common): validate statistics brief percentile metadata

### Which Issue(s) This PR Fixes

Closes issue 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.

Signed-off-by: dragonknightk <[email protected]>

Report URL: https://github.com/apache/rocketmq/actions/runs/45108541388

With regards,
GitHub Actions via GitBox

Reply via email to