fix(storage): Fixing watchOS crash when dealing with big files #3389
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #
Description
This PR changes
Int
toUInt64
in several Storage objects when representing bytes.watchOS's
Int
is actually aInt32
due to its arm64_32 architecture, so attempting to convert >= 2GB into bytes results in an overflown error.The only special handing is our usage of
FileHandle.read(upToCount:)
, which we use to split a file into parts for multipart uploads.Since the
count
attribute is anInt
, but the theoretical maximum size for a part is 5GB, attempting to directly cast it could crash. In practice, this very unlikely to happen as having a part with size >= 2GB with the current implementation can only happen for files of size bigger than 20TB.We can argue that by the time an Apple Watch can handle 20TB files, then the arm64_32 architecture would likely be long gone. But anyways, just to be extra cautious, I've prevented this situation by implementing a simple check that will "split" reads that exceed
Int.max
bytes.General Checklist
Given When Then
inline code documentation and are named accordinglytestThing_condition_expectation()
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.