Skip to content

Commit

Permalink
Networks and Sites: Ensure fileupload_maxk is an int to avoid pot…
Browse files Browse the repository at this point in the history
…ential fatal errors.

This changeset fixes a potential fatal error, for example when "Max upload file size" setting is set to an empty value. It also adds unit tests for `upload_size_limit_filter`.

Props mjkhajeh, bhrugesh12, SergeyBiryukov, kebbet, audrasjb, felipeelia.
Fixes #55926.

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


git-svn-id: http://core.svn.wordpress.org/trunk@54041 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
audrasjb committed Oct 11, 2022
1 parent 82d2620 commit ac36170
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -4771,6 +4771,7 @@ function sanitize_option( $option, $value ) {
case 'users_can_register':
case 'start_of_week':
case 'site_icon':
case 'fileupload_maxk':
$value = absint( $value );
break;

Expand Down
8 changes: 5 additions & 3 deletions wp-includes/ms-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2615,12 +2615,14 @@ function is_upload_space_available() {
* @return int Upload size limit in bytes.
*/
function upload_size_limit_filter( $size ) {
$fileupload_maxk = KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 );
$fileupload_maxk = (int) get_site_option( 'fileupload_maxk', 1500 );
$max_fileupload_in_bytes = KB_IN_BYTES * $fileupload_maxk;

if ( get_site_option( 'upload_space_check_disabled' ) ) {
return min( $size, $fileupload_maxk );
return min( $size, $max_fileupload_in_bytes );
}

return min( $size, $fileupload_maxk, get_upload_space_available() );
return min( $size, $max_fileupload_in_bytes, get_upload_space_available() );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.1-beta3-54481';
$wp_version = '6.1-beta3-54482';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit ac36170

Please sign in to comment.