SomeRandomiOSDev / CBORCoding

Easy CBOR encoding and decoding for iOS, macOS, tvOS and watchOS.
MIT License
49 stars 14 forks source link

Fix exception when parsing with sliced Data #16

Closed joskuijpers closed 3 years ago

joskuijpers commented 4 years ago

When a Data input is used that has a slice started beyond 0, an exception was thrown because the parser tried to access index 0.

See for example https://stackoverflow.com/questions/54698947/swift-data-subdata-fails-with-exc-bad-instruction-code-exc-i386-invop-subcode for an explanation.

All that was needed to fix it was to start at data.startIndex and finishes before data.endIndex. I also added a testcase that failed before my change and succeeds after my changes. The rest of the cases still run.

joskuijpers commented 4 years ago

Hmm no idea why it is failing. I removed the whitespace already...

SomeRandomiOSDev commented 3 years ago

@joskuijpers I pulled your commits and made a few additional updates to yours and merged it with PR https://github.com/SomeRandomiOSDev/CBORCoding/pull/18