[RigidArray, RigidDeque].nextSpan: Validate maximumCount

`nextSpan(after:,maximumCount:)` failed to validate that `maximumCount > 0`, potentially allowing out-of-bounds access.
This commit is contained in:
Karoy Lorentey committed 2026-02-16 15:54:49 -08:00
1 parent a446b47d6e
commit ac7a8bf61b
2 files changed
+3 -1

No files matched your search

@@ -310,7 +310,8 @@ extension RigidArray where Element: ~Copyable {
public func nextSpan(
after index: inout Int, maximumCount: Int
) -> Span<Element> {
precondition(index >= 0 && index <= _count, "Index out of bounds")
precondition(UInt(bitPattern: index) <= _count, "Index out of bounds")
precondition(maximumCount > 0, "maximumCount must be positive")
let start = index
index = start &+ Swift.min(maximumCount, _count &- start)
return _span(in: Range(uncheckedBounds: (start, index)))