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

[BUGFIX] Fix corrupted JavaScript assets loaded by website users #1919

Conversation

adamkoppede
Copy link
Contributor

Website users loaded corrupted JavaScript assets for files generated by EXT:vhs when EXT:vhs was in the middle of re-writing the contents of the requested asset file. This happens because EXT:core GeneralUtility::writeFile() isn't implemented in an atomic style causing observers (such as visiting website users) to read incomplete asset file contents. Incomplete JavaScript files likely cause syntax errors when interpreted by the user's user-agent rendering front end sites unable to reach JavaScript-based interactivity.

Fix the issue by (non-atomically) writing into a temporary file and replacing the destination asset file with a single atomic rename() operation instead. This ensures that observers of the destination asset file either see the complete old contents or the complete new contents but never any intermediate state of the asset content.

See: https://man7.org/linux/man-pages/man2/rename.2.html
See: https://github.com/TYPO3/typo3/blob/v10.4.37/typo3/sysext/core/Classes/Utility/GeneralUtility.php#L1835-L1861

Website users loaded corrupted JavaScript assets for files generated by
EXT:vhs when EXT:vhs was in the middle of re-writing the contents of the
requested asset file. This happens because EXT:core
`GeneralUtility::writeFile()` isn't implemented in an atomic style
causing observers (such as visiting website users) to read incomplete
asset file contents. Incomplete JavaScript files likely cause syntax
errors when interpreted by the user's user-agent rendering front end
sites unable to reach JavaScript-based interactivity.

Fix the issue by (non-atomically) writing into a temporary file and
replacing the destination asset file with a single atomic `rename()`
operation instead. This ensures that observers of the destination asset
file either see the complete old contents or the complete new contents
but never any intermediate state of the asset content.

See: https://man7.org/linux/man-pages/man2/rename.2.html
See: https://github.com/TYPO3/typo3/blob/v10.4.37/typo3/sysext/core/Classes/Utility/GeneralUtility.php#L1835-L1861
@NamelessCoder NamelessCoder force-pushed the bugfix/corrupted-javascript-asset-file-loaded-in-front-end branch from 6f49a19 to d3cf80d Compare December 4, 2024 09:10
@NamelessCoder NamelessCoder merged commit 0b648d4 into FluidTYPO3:development Dec 4, 2024
14 checks passed
@NamelessCoder
Copy link
Member

Thanks! Good edge-case catch.

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.

2 participants