valpackett / SwiftCBOR

A CBOR implementation for Swift
The Unlicense
132 stars 74 forks source link

UnkeyedDecodingContainer - corrupted data causes crash #69

Open skyfoxa opened 2 years ago

skyfoxa commented 2 years ago

Could we add a guard check before we touch data array with start and end indexes? We should throw an error if data doesn't contain requested range. It causes fatal error if data array doesn't contain range.startIndex..<(range.endIndex)

let container = _CBORDecoder.SingleValueContainer(data: self.data[range.startIndex..<(range.endIndex)], codingPath: self.codingPath, userInfo: self.userInfo)
hamchapman commented 2 years ago

A PR for this would be great - are you able to give it a go? Then I can review and we can get something merged