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

Possible data corruption using the AwsS3 driver #37844

Closed
1 of 5 tasks
ImanuelBertrand opened this issue Aug 4, 2023 · 12 comments · May be fixed by #37845
Closed
1 of 5 tasks

Possible data corruption using the AwsS3 driver #37844

ImanuelBertrand opened this issue Aug 4, 2023 · 12 comments · May be fixed by #37845
Assignees
Labels
Issue: needs update Additional information is require, waiting for response Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.6-p1 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it

Comments

@ImanuelBertrand
Copy link
Contributor

Preconditions and environment

  • Magento version: 2.4.6-p1 (but previous versions, too)
  • Enabled the AwsS3 driver for remote storage

Steps to reproduce

  1. Using the S3 adapter, open a (new) file and write AAAAA to it and close it.
  2. Open the file again, with mode w, and write BB to it.

Expected result

The expected result is that the AwsS3 driver works as a replacement for the base default implementation (File driver).
As documented by fopen for mode w is that the file should truncated and thus would now contain BB.

Actual result

The file contains BBAAA

Additional information

The root cause is that \Magento\AwsS3\Driver\AwsS3::fileOpen($path, $mode) does not check the $mode when opening the temporary stream.
It will always fetch the current contents of the object in S3, write it to the stream and then rewind the stream.
This effectively opens all files with mode r+, which is unexpected.

The impact of this is somehat migitated by the fact that the most common use of the adapter is saving image files, which are only written once and never directly overwritten.
Still, for any files that are updated (like product feeds), this can and will lead to data corruption.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
@m2-assistant
Copy link

m2-assistant bot commented Aug 4, 2023

Hi @ImanuelBertrand. Thank you for your report.
To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel.
⚠️ According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.
🕙 You can find the schedule on the Magento Community Calendar page.
📞 The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

@ImanuelBertrand
Copy link
Contributor Author

@magento I am working on this

@m2-assistant
Copy link

m2-assistant bot commented Aug 4, 2023

Hi @ImanuelBertrand! 👋
Thank you for collaboration. Only members of Community Contributors Team are allowed to be assigned to the issue. Please use @magento add to contributors team command to join Contributors team.

@ImanuelBertrand
Copy link
Contributor Author

@magento add to contributors team

@m2-assistant
Copy link

m2-assistant bot commented Aug 4, 2023

Hi @ImanuelBertrand! 👋
Thank you for joining. Please accept team invitation 👉 here 👈 and add your comment one more time.

@ImanuelBertrand
Copy link
Contributor Author

Adobe Commerce support developers have confirmed this issue (ticket #647575):

Our support developers have confirmed this issue is reproducible on a clean instance

@m2-community-project m2-community-project bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Aug 8, 2023
@engcom-Hotel engcom-Hotel added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label Aug 9, 2023
@m2-community-project m2-community-project bot added this to Pull Request In Progress in High Priority Backlog Aug 9, 2023
@m2-community-project m2-community-project bot removed this from Ready for Confirmation in Issue Confirmation and Triage Board Aug 9, 2023
@engcom-Hotel engcom-Hotel self-assigned this Aug 9, 2023
@m2-assistant
Copy link

m2-assistant bot commented Aug 9, 2023

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • 5. Add label Issue: Confirmed once verification is complete.
  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Hotel
Copy link
Contributor

Hello @ImanuelBertrand,

Thanks for the report and collaboration!

Can you please let us know if you are using a custom module or any third-party extension to write the files on S3, if possible please share this information with us.

Thanks

@engcom-Hotel engcom-Hotel added the Issue: needs update Additional information is require, waiting for response label Aug 9, 2023
@ImanuelBertrand
Copy link
Contributor Author

Hi @engcom-Hotel,

I came across the issue while testing the S3 storage for a client, using a custom Google product feed module.
Unfortunately, I can't share the full module, but it shouldn't be necessary.
The relevant code is this:
$this->filesystem->getDirectoryWrite('media')->writeFile($exportFilename, $data);

Depending on whether new file was smaller than the previous one, this would result in a broken XML file.

Regards
Imanuel

@abukatar
Copy link
Contributor

abukatar commented Aug 9, 2023

@magento I am working on this

@abukatar
Copy link
Contributor

abukatar commented Aug 9, 2023

An internal team is working on this issue right now (as Jira ticket ACP2E-2147)

@engcom-Bravo
Copy link
Contributor

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket ACP2E-2147 by the internal team
Related commits:https://github.com/search?q=repo%3Amagento%2Fmagento2+ACP2E-2147&type=commits

Based on the Jira ticket, the target version is 2.4.7-beta3.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response Issue: ready for confirmation Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reported on 2.4.6-p1 Indicates original Magento version for the Issue report. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Development

Successfully merging a pull request may close this issue.

5 participants