Repository navigation
Conversation
`wp_upload_bits()` ignores the results of `fwrite()` and `fclose()`. When only part of the data is written, the function still returns the file as a successful upload. The byte count is now compared with the length of the data, and the result of closing the stream is checked. As of PHP 8.6, `fclose()` returns `false` when flushing or closing the stream fails. In both cases the existing "Could not write file" error is returned.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
wp_upload_bits()ignores the results offwrite()andfclose(). When only part of the data is written, it still returns the file as a successful upload.This compares the byte count with the length of the data and checks the result of closing the stream. As of PHP 8.6,
fclose()returnsfalsewhen flushing or closing fails. In both cases the existing "Could not write file" error is returned.The partial file is left in place, as before. I am happy to add cleanup if that is preferred.
Testing
The new tests point the upload directory at
WP_Test_Streamthrough theupload_dirfilter and call the real function.tests/functions/wpUploadBits.phperrorisfalse(the flush test is skipped)tests/functions/wpUploadBits.php--group uploadPHPCS passes on the new test file and reports no errors on
functions.php.As with image saves, a userland stream wrapper with no
stream_flush()method fails on close on PHP 8.6, so it would now get this error.Related: #3659 adds general tests for this function.
Trac ticket: https://core.trac.wordpress.org/ticket/66786
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Used for: Finding the issue while reviewing unchecked stream writes, writing the change, the tests and this description, and running the tests. The test results above are automated runs by the tool.