Skip to content

Commit 06e8e70

Browse files
authored
Prevent arithmentic overflow when setting chunk content range value (#45)
1 parent 31d7484 commit 06e8e70

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: Sources/MuxUploadSDK/Upload/ChunkWorker.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,15 @@ fileprivate actor ChunkActor {
170170
let urlSession: URLSession
171171

172172
func upload() async throws -> URLResponse {
173-
let contentRangeValue = "bytes \(chunk.startByte)-\(chunk.endByte - 1)/\(chunk.totalFileSize)"
173+
let startByte = "\(chunk.startByte)"
174+
let endByte: String
175+
if chunk.endByte == 0 {
176+
endByte = "0"
177+
} else {
178+
endByte = "\(chunk.endByte - 1)"
179+
}
180+
181+
let contentRangeValue = "bytes \(startByte)-\(endByte)/\(chunk.totalFileSize)"
174182
var request = URLRequest(url: uploadURL)
175183
request.httpMethod = "PUT"
176184
request.setValue("video/*", forHTTPHeaderField: "Content-Type")

0 commit comments

Comments
 (0)