Networks and Sites: Ensure fileupload_maxk is an int to avoid potential 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.


git-svn-id: https://develop.svn.wordpress.org/trunk@54482 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2022-10-11 15:05:29 +00:00
parent e2c6f8c82a
commit 525d6d2a34
3 changed files with 54 additions and 3 deletions

View File

@@ -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() );
}
/**