Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix potential crash in ChunkedFile #38

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix potential crash in ChunkedFile
andrewjl-mux committed Jun 15, 2023

Verified

This commit was signed with the committer’s verified signature.
andrewjl-mux AJ Lauer Barinov
commit fc30ccbf6352a9f96937270866d55cdab93966dc
9 changes: 3 additions & 6 deletions Sources/MuxUploadSDK/InternalUtilities/ChunkedFile.swift
Original file line number Diff line number Diff line change
@@ -46,7 +46,9 @@ class ChunkedFile {
public func openFile(fileURL: URL) throws {
if fileHandle == nil {
do {
let fileSize = try readFileSize(url: fileURL)
guard let fileSize = try FileManager.default.attributesOfItem(atPath: fileURL.path)[FileAttributeKey.size] as? UInt64 else {
throw ChunkedFileError.invalidState("Cannot retrieve file size")
}
self._fileSize = fileSize

let handle = try FileHandle(forReadingFrom: fileURL)
@@ -103,11 +105,6 @@ class ChunkedFile {
return chunk
}

private func readFileSize(url: URL) throws -> UInt64 {
let fileAttr = try FileManager.default.attributesOfItem(atPath: url.path)
return fileAttr[FileAttributeKey.size] as! UInt64
}

/// Creates a ``ChunkedFile`` that wraps the file given by the URL. The file will be opened after calling ``openFile()``
init(chunkSize: Int) {
self.chunkSize = chunkSize