Skip to content

Commit 970994d

Browse files
2 parents 20a8632 + f99ee4a commit 970994d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Sources/CBORCoding/CBORParser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ internal class CBORParser {
1919
guard !data.isEmpty else { return nil }
2020

2121
var storage = Storage()
22-
var index: Int = 0
22+
var index: Int = data.startIndex
2323

2424
do {
25-
while index < data.count {
25+
while index < data.endIndex {
2626
let majorType = CBOR.majorType(for: data[index])
2727

2828
switch majorType {

Tests/CBORCodingTests/CBORParserTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,18 @@ class CBORParserTests: XCTestCase {
10741074

10751075
XCTAssertThrowsError(try CBORParser.testCreateCodingKey(from: UInt64.max))
10761076
}
1077+
1078+
func testSlicedDataInput() {
1079+
var value: Any!
1080+
1081+
// Skip over the first 2 bytes with a slice.
1082+
let data = convertFromHexString("0x000000")[2...]
1083+
1084+
XCTAssertNoThrow(value = try CBORParser.parse(data))
1085+
XCTAssertTrue(value is UInt64)
1086+
XCTAssertEqual(value as! UInt64, 0)
1087+
1088+
}
10771089

10781090
// MARK: Private Methods
10791091

0 commit comments

Comments
 (0)