Skip to content

Commit 2212cbe

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.
1 parent ab38db0 commit 2212cbe

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Sources/SwiftlyCore/HTTPClient.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ 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)
169+
let byteData = buffer.getData(at: buffer.readerIndex, length: buffer.readableBytes)
170+
if let data = byteData {
171+
try fileHandle.write(contentsOf: data)
171172
}
172173

173174
let now = Date()

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)