Skip to content

Reject ring buffer sizes above 2^30 with ArgumentOutOfRangeException [patch] - #114

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/89-ring-buffer-size-limit
Oct 13, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/89-ring-buffer-size-limit

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #89

What changed

  • RingBuffer<T>: the constructors, Resize and Resample now throw ArgumentOutOfRangeException for a length above 2^30. Before, they threw an undocumented OverflowException from new T[int.MinValue].
  • RingBuffer.AllocateBuffer creates the new array before it assigns any field. A rejected Resize or Resample now leaves the buffer and its contents as they were. Before, it left Capacity at int.MinValue, so the next PushBack calls indexed past the end of the array.
  • SpscRingBuffer<T> and DelayLine throw ArgumentOutOfRangeException for a capacity above 2^30 − 1, because they need one extra slot.
  • The XML docs state these limits.

Tests

  • Constructor_LengthAbove2Pow30_Throws, Resize_LengthAbove2Pow30_ThrowsAndLeavesBufferUnchanged and Resample_LengthAbove2Pow30_ThrowsAndLeavesBufferUnchanged in RingBufferTests.
  • Constructor_CapacityAbove2Pow30Minus1_Throws in SpscRingBufferTests and in DelayLineTests.

With the library change reverted, all 5 new tests fail. With it applied, the full suite passes: 480 of 480. The library builds with no warnings on every target framework.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TsgfXrtMpBX5Yc7dZ9GY3v


Generated by Claude Code

…[patch]

RingBuffer, SpscRingBuffer and DelayLine rounded their size up to a
power of two without an upper bound, so a size above 2^30 wrapped to
int.MinValue and threw an undocumented OverflowException. Validate the
upper bound up front and document it. RingBuffer also allocates its new
array before assigning any field, so a rejected Resize or Resample
leaves the buffer and its contents intact.

Fixes #89

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TsgfXrtMpBX5Yc7dZ9GY3v
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants