Skip to content

Commit eb300f2

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. Construct Swiftly's own HTTPClient with the default decompression configuration since the shared one exhibits a decompression limit error with the GitHub API's.
1 parent ab38db0 commit eb300f2

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

Sources/SwiftlyCore/HTTPClient.swift

+2-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,5 @@ public struct SwiftlyHTTPClient {
185183
}
186184

187185
private class HTTPClientWrapper {
188-
fileprivate let inner = HTTPClient.shared
186+
fileprivate let inner = HTTPClient(eventLoopGroupProvider: .singleton)
189187
}

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)