Closed swift-ci closed 5 years ago
wow, this is bad. CC @millenomi/ianpartridge (JIRA User)/@spevans
Note this affects 5.0.2 but 5.1 and master
are unaffected - there have been serveral PRs to fix HTTPCookie
issues including parsing that went into master
post 5.0.
The 5.1 changes are standalone, IIRC. We should nominate a backport to 5.0.3. @weissi?
Awesome, the merge window is open right now. I'm more than happy to accept a backport for this.
@weissi @spevans https://github.com/apple/swift-corelibs-foundation/pull/2467
Attachment: Download
Environment
Swift 5.0.2 using the official swift:5.0.2 Docker image.Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 1 | |Component/s | Foundation | |Labels | Bug, Linux, RunTimeCrash | |Assignee | @millenomi | |Priority | Medium | md5: d9768b4cd9f0c26fef747e98c5ada8a6Issue Description:
tl;dr version
When using URLSession to perform HTTP requests, there is an edge case that works on macOS, but causes the process to terminate with illegal instruction on Linux.
If the server response contains a trailing semicolon in a Set-Cookie header, the
HTTPCookie.cookies(withResponseHeaderFields:for:)
method crashes.One liner reproduction:
Long version
Consider the following Swift code that uses URLSession (inside):
On macOS, the code executes perfectly fine and prints the XML data.
On Linux (official Swift 5.0.2 docker image), the process crashes and dumps a stacktrace instead:
The stacktrace is a bit different on 4.2.4, but still originates from the same
HTTPCookie.cookies(withResponseHeaderFields:for:)
method.While inspecting the response from the mentioned URL with
curl -v
, the Set-Cookie headers became suspicious. Particularly, the semicolons after each line:To test this suspicion, I hacked together a small hello-world-like Node.js script (attached as index.js).
Running it on macOS while pointing the test Swift code running in Docker at
host.docker.internal:3000
allowed me to test how URLSession behaves depending on the headers.I confirmed that if the semicolon is at the end of the header, HTTPCookie crashes; and by removing the extra semicolon the crash disappears as well.