WordPress/wp-admin
iandunn 4de6175227 Multisite: Cache absolute dirsize paths to avoid PHP 8 fatal.
r49212 greatly improved the performance of `get_dirsize()`, but also changed the structure of the data stored in the `dirsize_cache` transient. It stored relative paths instead of absolute ones, and also removed the unnecessary `size` array.

That difference in data structures led to a fatal error in the following environment:

* PHP 8
* Multisite
* A custom `WP_CONTENT_DIR` which is not a child of WP's `ABSPATH` folder (e.g., [https://roots.io/bedrock/ Bedrock])
* The `upload_space_check_disabled` option set to `0`

After upgrading to WP 5.6, the `dirsize_cache` transient still had data in the old format. When `wp-admin.php/index.php` was visited, `get_space_used()` received an `array` instead of an `int`, and tried to divide it by another `int`. PHP 7 would silently cast the arguments to match data types, but [https://wiki.php.net/rfc/arithmetic_operator_type_checks PHP 8 throws a fatal error]: 

`Uncaught TypeError: Unsupported operand types: array / int`

`recurse_dirsize()` was using `ABSPATH` to convert the absolute paths to relative ones, but some upload locations are not located under `ABSPATH`. In those cases, `$directory` and `$cache_path` were identical, and that triggered the early return of the old `array`, instead of the expected `int`. 

In order to avoid that, this commit restores the absolute paths, but without the `size` array. It also adds a type check when returning cached values. Using absolute paths without `size` has the result of overwriting the old data, so that it matches the new format. The type check and upgrade routine are additional safety measures.

Props peterwilsoncc, janthiel, helen, hellofromtonya, francina, pbiron.
Fixes #51913. See #19879.


Built from https://develop.svn.wordpress.org/trunk@49744


git-svn-id: http://core.svn.wordpress.org/trunk@49467 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-12-03 20:39:02 +00:00
..
css Help/About: WordPress 5.6 About Page. 2020-11-17 21:34:04 +00:00
images About: Optimize freedoms sprite and add 2 column layout. 2020-11-02 19:46:14 +00:00
includes Multisite: Cache absolute dirsize paths to avoid PHP 8 fatal. 2020-12-03 20:39:02 +00:00
js Site Health, App Passwords: Ensure REST API responses are properly translated. 2020-12-01 03:44:05 +00:00
maint Administration: Remove the xmlns attribute on the <html> tag. 2020-06-22 21:26:16 +00:00
network Coding standards: Modify escaping functions to avoid potential false positives. 2020-10-29 18:03:11 +00:00
user
about.php Help/About: Update URLs in About page 2020-11-27 17:10:07 +00:00
admin-ajax.php Site Health, REST API: Move async tests to REST API endpoints. 2020-10-15 02:00:08 +00:00
admin-footer.php
admin-functions.php
admin-header.php Coding standards: Modify escaping functions to avoid potential false positives. 2020-10-29 18:03:11 +00:00
admin-post.php
admin.php Upgrade/Install: Don't trigger database upgrade on Ajax requests via wp-admin/async-upload.php. 2020-07-22 12:56:04 +00:00
async-upload.php General: Replace older-style PHP type conversion functions with type casts. 2020-10-08 21:15:13 +00:00
authorize-application.php App Passwords: Unify availability language. 2020-11-16 22:42:04 +00:00
comment.php Docs: Update the URL for PHP date formats table in translator comments. 2020-09-18 10:37:08 +00:00
credits.php Help/About: WordPress 5.6 About Page. 2020-11-17 21:34:04 +00:00
custom-background.php
custom-header.php
customize.php Docs: Correct documentation for customize_controls_head hook and _customizer_mobile_viewport_meta() function. 2020-07-10 11:36:07 +00:00
edit-comments.php Comments: Correct ending tag placement in the "Search results for: ..." subtitle. 2020-11-28 17:28:05 +00:00
edit-form-advanced.php Docs: Update the URL for PHP date formats table in translator comments. 2020-09-18 10:37:08 +00:00
edit-form-blocks.php Editor: Hide Screen Options tab from block editor 2020-09-24 03:00:08 +00:00
edit-form-comment.php Docs: Update the URL for PHP date formats table in translator comments. 2020-09-18 10:37:08 +00:00
edit-link-form.php Administration: Use HTTPS for XHTML Friends Network URL. 2020-07-04 09:33:01 +00:00
edit-tag-form.php Docs: Fix and upgrade various object docblock notations. 2020-10-17 16:05:09 +00:00
edit-tags.php Coding Standards: Split long printf() calls for search results for better readability. 2020-10-23 17:19:14 +00:00
edit.php Coding Standards: Split long printf() calls for search results for better readability. 2020-10-23 17:19:14 +00:00
erase-personal-data.php Privacy: Improve clarity of privacy error strings. 2020-10-04 03:23:09 +00:00
export-personal-data.php Privacy: Set the direction for the "Username or email address" field on privacy screens to LTR. 2020-07-14 11:17:04 +00:00
export.php
freedoms.php Help/About: WordPress 5.6 About Page. 2020-11-17 21:34:04 +00:00
import.php I18N: Add context to some plugin and theme strings for consistency. 2020-07-20 23:14:05 +00:00
index.php Help/About: Add Site Health Status dashboard widget to the Help → Content tab. 2020-11-10 19:05:10 +00:00
install-helper.php
install.php Site Health: Improve the error message displayed when activating a plugin that requires a higher version of PHP or WordPress. 2020-06-26 00:27:09 +00:00
link-add.php
link-manager.php Coding Standards: Split long printf() calls for search results for better readability. 2020-10-23 17:19:14 +00:00
link-parse-opml.php XML-RPC: Explicitly unset the reference to the parser resource after calling xml_parser_free() to avoid memory leaks in PHP 7.0.0 or higher. 2020-07-05 15:22:01 +00:00
link.php Coding Standards: Replace alias PHP functions with the canonical names. 2020-10-18 17:27:06 +00:00
load-scripts.php
load-styles.php
media-new.php Coding standards: Modify escaping functions to avoid potential false positives. 2020-10-29 18:03:11 +00:00
media-upload.php General: Replace older-style PHP type conversion functions with type casts. 2020-10-08 21:15:13 +00:00
media.php
menu-header.php Coding Standards: Replace alias PHP functions with the canonical names. 2020-10-18 17:27:06 +00:00
menu.php
moderation.php
ms-admin.php
ms-delete-site.php Docs: Various docblock improvements related to user and site signup functionality. 2020-09-30 21:54:07 +00:00
ms-edit.php
ms-options.php
ms-sites.php
ms-themes.php
ms-upgrade-network.php
ms-users.php
my-sites.php
nav-menus.php Administration: Better targeting for required form field highlighting. 2020-10-23 15:05:09 +00:00
network.php
options-discussion.php General: Update code for readability and inclusion 2020-07-23 03:14:06 +00:00
options-general.php Docs: Update the URL for PHP date formats table in translator comments. 2020-09-18 10:37:08 +00:00
options-head.php
options-media.php
options-permalink.php Permalinks: Don't show "You should update your .htaccess file now" message when saving permalink settings on Multisite. 2020-08-02 12:57:08 +00:00
options-privacy.php Privacy: Improve clarity of privacy error strings. 2020-10-04 03:23:09 +00:00
options-reading.php Help/About: Clarify that discouraging search engines does not prevent them from crawling the site. 2020-10-23 18:07:13 +00:00
options-writing.php Administration: Add missing comma to the message in "Post via email" section. 2020-06-26 19:38:06 +00:00
options.php General: Update code for readability and inclusion 2020-07-23 03:14:06 +00:00
plugin-editor.php Coding Standards: Replace alias PHP functions with the canonical names. 2020-10-18 17:27:06 +00:00
plugin-install.php Accessibility: Plugins: Accessibility and CSS improvements for the Plugins pages. 2020-07-03 08:51:05 +00:00
plugins.php Plugins: Check if _error_nonce is set before attempting to verify it. 2020-11-23 13:36:07 +00:00
post-new.php
post.php Posts, Post Types: Switch to restoring posts to draft status by default when they are untrashed. 2020-10-11 13:39:07 +00:00
press-this.php
privacy-policy-guide.php Privacy: Improve clarity of privacy error strings. 2020-10-04 03:23:09 +00:00
privacy.php Help/About: WordPress 5.6 About Page. 2020-11-17 21:34:04 +00:00
profile.php
revision.php Text Changes: Unify various "Back to..." vs. "Return to..." vs. "Go to..." strings. 2020-11-09 10:53:10 +00:00
setup-config.php Docs: Upgrade more parameters in docblocks to used typed array notation. 2020-11-24 21:27:05 +00:00
site-health-info.php Accessibility: Site Health: Improve the "Copy site info" button accessibility. 2020-06-30 13:26:03 +00:00
site-health.php Site Health: Validate the test result data format in JS before using it. 2020-11-08 09:52:10 +00:00
term.php
theme-editor.php Coding Standards: Replace alias PHP functions with the canonical names. 2020-10-18 17:27:06 +00:00
theme-install.php Themes: Display a message in theme grid if a theme requires a higher version of PHP or WordPress. 2020-07-27 15:04:03 +00:00
themes.php Upgrade/Install: Only show auto-update for themes that support the feature. 2020-07-29 20:01:08 +00:00
tools.php
update-core.php Upgrade/Install: Display "You are using a development version" message on WordPress Updates screen for Beta or RC versions. 2020-11-30 13:42:07 +00:00
update.php Upgrade/Install: Ensure cleanup after canceled update. 2020-07-10 06:08:06 +00:00
upgrade-functions.php
upgrade.php Site Health: Improve the error message displayed when activating a plugin that requires a higher version of PHP or WordPress. 2020-06-26 00:27:09 +00:00
upload.php Coding Standards: Split long printf() calls for search results for better readability. 2020-10-23 17:19:14 +00:00
user-edit.php App Passwords: MOAR accessibility improvements. 2020-11-12 18:14:08 +00:00
user-new.php Coding Standards: Remove unused $current_role variable from Add New User form. 2020-10-24 12:49:05 +00:00
users.php Coding Standards: Split long printf() calls for search results for better readability. 2020-10-23 17:19:14 +00:00
widgets.php Accessibility: Widgets: Add a "Cancel" link when editing a widget in accessibility mode. 2020-10-09 15:53:08 +00:00