File tree Expand file tree Collapse file tree
src/Adaptive.Agrona/Concurrent/Status Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -456,7 +456,12 @@ public string GetCounterLabel(int counterId)
456456
457457 protected void ValidateCounterId ( int counterId )
458458 {
459- if ( counterId < 0 || counterId > MaxCounterId )
459+ // .NET's MaxCounterId is one-past-max (capacity / COUNTER_LENGTH), used as the
460+ // upper bound in `for (i = 0; i < MaxCounterId; i++)` iteration loops throughout
461+ // the codebase. So a counterId equal to MaxCounterId is out of bounds — it would
462+ // produce CounterOffset(counterId) == capacity and a buffer-overrun read.
463+ // Java's maxCounterId is one less (inclusive max) and uses `> maxCounterId` here.
464+ if ( counterId < 0 || counterId >= MaxCounterId )
460465 {
461466 throw new System . ArgumentException (
462467 "Counter id " + counterId + " out of range: maxCounterId=" + MaxCounterId
You can’t perform that action at this time.
0 commit comments