Skip to content

Commit f84dd35

Browse files
committed
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 security fixes that could have an impact on swiftly. Revert the changes to the SwiftlyHTTPClient that changed it to use the shared async HTTPClient. That broke the interactions with the GitHub REST API's.
1 parent ab38db0 commit f84dd35

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Sources/SwiftlyCore/HTTPClient.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ public struct SwiftlyHTTPClient {
166166
for try await buffer in response.body {
167167
receivedBytes += buffer.readableBytes
168168

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

173171
let now = Date()
174172
if let reportProgress, lastUpdate.distance(to: now) > 0.25 || receivedBytes == expectedBytes {
@@ -185,5 +183,9 @@ public struct SwiftlyHTTPClient {
185183
}
186184

187185
private class HTTPClientWrapper {
188-
fileprivate let inner = HTTPClient.shared
186+
fileprivate let inner = HTTPClient(eventLoopGroupProvider: .singleton)
187+
188+
deinit {
189+
try? self.inner.syncShutdown()
190+
}
189191
}

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)