Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5209] Searching a Data slice with default range results in a crash #3845

CharlesJS opened this issue Jun 13, 2017 · 3 comments


Copy link

CharlesJS commented Jun 13, 2017

Previous ID SR-5209
Radar rdar://problem/36261057
Original Reporter @CharlesJS
Type Bug
Additional Detail from JIRA
Votes 2
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: f61c821c7374601c9542542c2b5e3bfb

Issue Description:

When searching a Data object that is a slice of another Data object, the default value for the 'range' parameter becomes the bounds of the parent data, rather than the slice. This results in a crash when trying to search using range(of:), as you can see by running the code below:

import Foundation

let data = "FooBar".data(using: .ascii)!
let slice = data[3...] // Bar

let range = slice.range(of: "a".data(using: .ascii)!) // Crash! NSRangeException: range {0, 6} exceeds data length 3
Copy link

belkadan commented Jun 13, 2017

cc @phausler

Copy link

karwa commented Dec 26, 2017

+1, still occurs in Swift 4.0.3

import Foundation
let dataOne = Data(0..<100)
let dataTwo = Data(25..<30)
dataOne.range(of: dataTwo) // returns: .some(25..<30)
dataOne.subdata(in: 10..<90).range(of: dataTwo) // returns: .some(15..<20)
dataOne[10..<90].range(of: dataTwo) // CRASH!

Copy link

belkadan commented Jan 2, 2018

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

3 participants