Skip to content

Commit

Permalink
Memory safety and security fixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmcgee1024 committed Jun 14, 2024
1 parent ab38db0 commit f84dd35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Sources/SwiftlyCore/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ public struct SwiftlyHTTPClient {
for try await buffer in response.body {
receivedBytes += buffer.readableBytes

try buffer.withUnsafeReadableBytes { bufferPtr in
try fileHandle.write(contentsOf: bufferPtr)
}
try fileHandle.write(contentsOf: buffer.readableBytesView)

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

private class HTTPClientWrapper {
fileprivate let inner = HTTPClient.shared
fileprivate let inner = HTTPClient(eventLoopGroupProvider: .singleton)

deinit {
try? self.inner.syncShutdown()
}
}
2 changes: 1 addition & 1 deletion scripts/install-libarchive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -o errexit

# TODO detect platform
LIBARCHIVE_VERSION=3.6.1
LIBARCHIVE_VERSION=3.7.4

mkdir /tmp/archive-build
pushd /tmp/archive-build
Expand Down

0 comments on commit f84dd35

Please sign in to comment.