Validate negative startIndex in ObservableList.RemoveRange#9
Merged
VPDPersonal merged 1 commit intoMay 22, 2026
Merged
Conversation
Throw ArgumentOutOfRangeException before taking the lock, matching the existing count guard, so callers get a deterministic exception instead of an IndexOutOfRangeException from the per-item read at items[i] = _list[startIndex + i].
4ef0508
into
fix/observable-incremental-and-review
1 check passed
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.
Summary
Adds a
startIndex < 0guard toObservableList<T>.RemoveRange(int startIndex, int count)(Runtime/Observable/ObservableList.cs:171), alongside the existingcount < 0check and before thelock (SyncRoot). Without it, a negativestartIndexwould fall through to_list[startIndex + i]inside the lock and surface asIndexOutOfRangeException(orArgumentOutOfRangeExceptionfrom the underlying list) — depending oncount, possibly only after partially observing the wrong slice.With the guard, callers now get a deterministic
ArgumentOutOfRangeException(nameof(startIndex))up front, mirroring the BCLList<T>.RemoveRangecontract and the siblingcountcheck that already exists one line below.Notes for review
countguard, so there is no risk of holdingSyncRootwhile throwing.count < 0, which is already covered by the existingRemoveRangenegative-input tests; the same shape applies here.Test plan
Aspid.Collections.Observable.Tests— full EditMode suite still passes.new ObservableList<int> { 1, 2, 3 }.RemoveRange(-1, 0)throwsArgumentOutOfRangeExceptionwithParamName = "startIndex".Generated by Claude Code