Skip to content

Commit 5f53ffb

Browse files
committed
Fix merge issue with _body; prevent creation of a protocol object if resume data is invalid.
1 parent 1bf1656 commit 5f53ffb

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Foundation/URLSession/URLSession.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ fileprivate extension URLSession {
545545

546546
guard !self.invalidated else { fatalError("Session invalidated") }
547547
let task = URLSessionDownloadTask()
548+
task.createdFromInvalidResumeData = true
548549
task.taskIdentifier = createNextTaskIdentifier()
549550
task.session = self
550551
workQueue.async {

Foundation/URLSession/URLSessionTask.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ open class URLSessionTask : NSObject, NSCopying {
9898

9999
internal var actualSession: URLSession? { return session as? URLSession }
100100
internal var session: URLSessionProtocol! //change to nil when task completes
101-
internal let body: _Body
102-
101+
103102
fileprivate enum ProtocolState {
104103
case toBeCreated
105104
case awaitingCacheReply(Bag<(URLProtocol?) -> Void>)
@@ -612,6 +611,17 @@ open class URLSessionUploadTask : URLSessionDataTask {
612611
*/
613612
open class URLSessionDownloadTask : URLSessionTask {
614613

614+
var createdFromInvalidResumeData = false
615+
616+
// If a task is created from invalid resume data, prevent attempting creation of the protocol object.
617+
override func _getProtocol(_ callback: @escaping (URLProtocol?) -> Void) {
618+
if createdFromInvalidResumeData {
619+
callback(nil)
620+
} else {
621+
super._getProtocol(callback)
622+
}
623+
}
624+
615625
internal var fileLength = -1.0
616626

617627
/* Cancel the download (and calls the superclass -cancel). If

0 commit comments

Comments
 (0)