Repository navigation
Reject ring buffer sizes above 2^30 with ArgumentOutOfRangeException [patch] - #114
Merged
Merged
Conversation
…[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
|
This was referenced Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #89
What changed
RingBuffer<T>: the constructors,ResizeandResamplenow throwArgumentOutOfRangeExceptionfor a length above 2^30. Before, they threw an undocumentedOverflowExceptionfromnew T[int.MinValue].RingBuffer.AllocateBuffercreates the new array before it assigns any field. A rejectedResizeorResamplenow leaves the buffer and its contents as they were. Before, it leftCapacityatint.MinValue, so the nextPushBackcalls indexed past the end of the array.SpscRingBuffer<T>andDelayLinethrowArgumentOutOfRangeExceptionfor a capacity above 2^30 − 1, because they need one extra slot.Tests
Constructor_LengthAbove2Pow30_Throws,Resize_LengthAbove2Pow30_ThrowsAndLeavesBufferUnchangedandResample_LengthAbove2Pow30_ThrowsAndLeavesBufferUnchangedinRingBufferTests.Constructor_CapacityAbove2Pow30Minus1_ThrowsinSpscRingBufferTestsand inDelayLineTests.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