Skip to content

[URLSession]Fix a crash in _HTTPBodyDataSource.getNextChunk() #854

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

Merged
merged 1 commit into from
Feb 1, 2017

Conversation

pushkarnk
Copy link
Member

I came across this bug while investigating another URLSession failure. URLSession uses the CURLOPT_READFUNCTION callback to write data to a socket during uploads. This writing happens in chunks of 16K. The getNextChunk is used to split the body which is wrapped in DispatchData into a writable chunk (typically 16K with libcurl) and the remaining data. When the remaining data is lesser than 16K, we do not split the data and send it as is, making sure that the next call to getNextChunk will indicate completion (return length = 0). However, because we set data to nil, the last call to getNextChunk in a large transfer is bound to crash here.

Instead of setting data to nil we can set it to DispatchData.empty. It looks like this was the intention in the original PR but we seemed to have introduced this bug while updating PR 299 for the new Dispatch API in Swift 3.

@parkera
Copy link
Contributor

parkera commented Jan 31, 2017

Looks good to me.

@pushkarnk
Copy link
Member Author

Thanks @parkera

@swift-ci please test and merge

@swift-ci swift-ci merged commit 2c75086 into swiftlang:master Feb 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants