mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
[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:
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)))
|
||||
|
||||
Reference in new issue
Block a user