Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix s3 v3 multipart overwrite when key exists #9388

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

Merged
merged 2 commits into from
Oct 19, 2023
Merged

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Oct 18, 2023

Motivation

Reported in #9387: when creating a multipart upload on an existing key, we would not truncate the key before overwrite it like we do when calling PutObject.

This was due to our optimization with append on the StoredS3Object, which was stateless, and bad oversight on my side.

Flow for the sample in the linked issue is:

  • CreateMultipart on key test
  • UploadPart with value "first"
  • CompletePart on key test
  • GetObject on key test -> value is "first"
  • CreateMultipart again on key test
  • UploadPart with the result of previous GetObject ("first") + "second" -> value = "firstsecond"
  • CompleteMultipart on key test
  • GetObject on key test, result should be "firstsecond"

Issue was appending on top of existing key, resulting in "firstfirstsecond".

Changes

Added a new truncate method to the base S3StoredObject to be able to reset the file from the StoredMultipart.
Add s3_object.seek(0) + s3_object.truncate() in complete_multipart so that the existing file object representing the key is properly truncated before we write and we do not append the multipart on top of the existing key.

Added an AWS validated test validating this behaviour.

@bentsku bentsku added aws:s3 Amazon Simple Storage Service semver: patch Non-breaking changes which can be included in patch releases labels Oct 18, 2023
@bentsku bentsku requested a review from thrau October 18, 2023 15:46
@bentsku bentsku self-assigned this Oct 18, 2023
@bentsku bentsku requested a review from macnev2013 as a code owner October 18, 2023 15:46
@bentsku bentsku linked an issue Oct 18, 2023 that may be closed by this pull request
@coveralls
Copy link

Coverage Status

coverage: 83.0% (+0.007%) from 82.993% when pulling f9b2be0 on fix-s3-v3-multipart into aed660e on master.

@github-actions
Copy link

LocalStack Community integration with Pro

       2 files         2 suites   1h 14m 51s ⏱️
2 258 tests 1 754 ✔️ 504 💤 0
2 259 runs  1 754 ✔️ 505 💤 0

Results for commit f9b2be0.

Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

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

nice catch, easy to miss!

@bentsku bentsku merged commit e4a6b64 into master Oct 19, 2023
@bentsku bentsku deleted the fix-s3-v3-multipart branch October 19, 2023 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:s3 Amazon Simple Storage Service semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S3 V3 issue with aws-s3 docker storage driver
3 participants