Skip to content

Commit 245d869

Browse files
authored
Update usage of unsafe API, upgrade libarchive to 3.7.4, upgrade async http client (#120)
Memory safety and security fixes Reduce the use of unsafe swift constructs in favour of ones that are memory safe. In the HTTP client remove the use of the unsafe mutable pointer in favour of direct Data conversion before writing the downloaded file to disk. Upgrade the version of libarchive to 3.7.4, which includes some fixes. Fix the changes to the SwiftlyHTTPClient that changed it to use the shared async HTTPClient. That broke the interactions with the GitHub REST API's. Update to the new async http client that fixes problems with decompression limits. Co-authored-by: Chris (SPG) McGee <[email protected]>
1 parent ab38db0 commit 245d869

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

Package.resolved

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2+
"originHash" : "4e45e73ff02865a9bd0426ba4c6cd8dfcb967e62e7663128dd262908109e1487",
23
"pins" : [
34
{
45
"identity" : "async-http-client",
56
"kind" : "remoteSourceControl",
67
"location" : "https://github.com/swift-server/async-http-client",
78
"state" : {
8-
"revision" : "fb308ee72f3d4c082a507033f94afa7395963ef3",
9-
"version" : "1.21.0"
9+
"revision" : "0ae99db85b2b9d1e79b362bd31fd1ffe492f7c47",
10+
"version" : "1.21.2"
1011
}
1112
},
1213
{
@@ -136,5 +137,5 @@
136137
}
137138
}
138139
],
139-
"version" : 2
140+
"version" : 3
140141
}

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
],
1414
dependencies: [
1515
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
16-
.package(url: "https://github.com/swift-server/async-http-client", from: "1.21.0"),
16+
.package(url: "https://github.com/swift-server/async-http-client", from: "1.21.2"),
1717
.package(url: "https://github.com/apple/swift-nio.git", from: "2.64.0"),
1818
.package(url: "https://github.com/apple/swift-tools-support-core.git", from: "0.6.1"),
1919
],

Sources/SwiftlyCore/HTTPClient.swift

+2-10
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ public protocol HTTPRequestExecutor {
1111

1212
/// An `HTTPRequestExecutor` backed by an `HTTPClient`.
1313
internal struct HTTPRequestExecutorImpl: HTTPRequestExecutor {
14-
fileprivate static let client = HTTPClientWrapper()
15-
1614
public func execute(_ request: HTTPClientRequest, timeout: TimeAmount) async throws -> HTTPClientResponse {
17-
try await Self.client.inner.execute(request, timeout: timeout)
15+
try await HTTPClient.shared.execute(request, timeout: timeout)
1816
}
1917
}
2018

@@ -166,9 +164,7 @@ public struct SwiftlyHTTPClient {
166164
for try await buffer in response.body {
167165
receivedBytes += buffer.readableBytes
168166

169-
try buffer.withUnsafeReadableBytes { bufferPtr in
170-
try fileHandle.write(contentsOf: bufferPtr)
171-
}
167+
try fileHandle.write(contentsOf: buffer.readableBytesView)
172168

173169
let now = Date()
174170
if let reportProgress, lastUpdate.distance(to: now) > 0.25 || receivedBytes == expectedBytes {
@@ -183,7 +179,3 @@ public struct SwiftlyHTTPClient {
183179
try fileHandle.synchronize()
184180
}
185181
}
186-
187-
private class HTTPClientWrapper {
188-
fileprivate let inner = HTTPClient.shared
189-
}

scripts/install-libarchive.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -o errexit
44

55
# TODO detect platform
6-
LIBARCHIVE_VERSION=3.6.1
6+
LIBARCHIVE_VERSION=3.7.4
77

88
mkdir /tmp/archive-build
99
pushd /tmp/archive-build

0 commit comments

Comments
 (0)