Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: validate uploaded parts before completing upload #13763

Open
wants to merge 4 commits into
base: storage-browser/integrity
Choose a base branch
from

Conversation

eppjame
Copy link

@eppjame eppjame commented Aug 28, 2024

Description of changes

  • Simplify string size evaluation in byteLength to align with upload part generator. When validating parts, it's required to have the same size calculation. Other data types are already aligned.
  • Before sending CompleteMultipartUpload, validate that we have all expected parts based on object size.

Issue #, if available

Description of how you validated changes

  • New unit tests mocking cache to create invalid parts

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@eppjame eppjame requested a review from a team as a code owner August 28, 2024 20:10
@@ -8,16 +8,9 @@
export const byteLength = (input?: any): number | undefined => {
if (input === null || input === undefined) return 0;
if (typeof input === 'string') {
let len = input.length;
const blob = new Blob([input]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worried this might introduce compatibility issues on RN. What was wrong with the old logic for string inputs?

Copy link
Author

@eppjame eppjame Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just aligning the length evaluation with getDataChunker.
I was concerned at the possibility of byteLength and getDataChunker determining different sizes.
There shouldn't be any issue with RN, because it already has to work in getDataChunker. Unless there is an expected RN limitation to singlepart uploads.

@@ -193,6 +195,8 @@ export const getMultipartUploadHandlers = (
});
}

validateCompletedParts(inProgressUpload.completedParts, size!);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to coerce the size? Maybe we should only run the validation if size is set. Specifically from the inline docs on byteLength: "The total size is not required for multipart upload, as it's only used in progress report." If we do want to make sure this always run, can we just update the types to not require the assertion?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byteLength is a bit odd, because in any case where it would return undefined the upload is rejected by getDataChunker.
For any valid multipart upload, byteLength must be able to determine size, which makes sense because we can't do a multipart upload without knowing the size.

I considered updating byteLength to throw if it can't determine size, but it would change behaviour of that failure case and takes more refactoring.

As for only used in progress report, it's used throughout the upload process.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks for the explanation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here,

  1. what happens here when the size is undefined for some reason? i m still unclear on that.
  2. As for only used in progress report, it's used throughout the upload process.
    for this, can we update inline docs accordingly then?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If size is undefined, the upload will default to a multipart upload. When it gets to getDataChunker, it will throw an error and upload will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants