Skip to content

Commit

Permalink
Handle large payloads on 32bit platforms gracefully (#29)
Browse files Browse the repository at this point in the history
Handle large payloads on 32bit platforms gracefully

### Motivation

If there's a request payload with a number of bytes that can't fit into 32 bits, we'd crash.

### Modifications

Use a graceful initializer and use `.unknown` (so no `content-length` will be sent) if the size exceeds the max of a 32bit int.

### Result

No crash for large payloads on 32bit platforms.

### Test Plan

Tests pass.


Reviewed by: dnadoba

Builds:
     ✔︎ pull request validation (5.10) - Build finished. 
     ✔︎ pull request validation (5.9) - Build finished. 
     ✔︎ pull request validation (nightly) - Build finished. 
     ✔︎ pull request validation (soundness) - Build finished. 

#29
  • Loading branch information
czechboy0 authored Nov 28, 2023
1 parent f5bf294 commit 0859ead
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public struct AsyncHTTPClientTransport: ClientTransport {
let length: HTTPClientRequest.Body.Length
switch body.length {
case .unknown: length = .unknown
case .known(let count): length = .known(Int(count))
case .known(let count):
if let intValue = Int(exactly: count) { length = .known(intValue) } else { length = .unknown }
}
clientRequest.body = .stream(body.map { .init(bytes: $0) }, length: length)
}
Expand Down

0 comments on commit 0859ead

Please sign in to comment.