Index: src/wp-includes/media.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/wp-includes/media.php	(revision 35390)
+++ src/wp-includes/media.php	(revision )
@@ -2602,24 +2602,60 @@
 /**
  * Determines the maximum upload size allowed in php.ini.
  *
+ * The optional arguments should be supplied only for testing
+ * the function.
+ *
  * @since 2.5.0
+ * @since 4.4.0 Introduced the `$upl_max_filesize_bytes` and `$post_max_size_bytes` parameters.
  *
+ * @param int $upl_max_filesize_bytes A value for upload_max_filesize.
+ * @param int $post_max_size_bytes A value for post_max_size.
+ *
  * @return int Allowed upload size.
  */
-function wp_max_upload_size() {
-	$u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
-	$p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
+function wp_max_upload_size( $upl_max_filesize_bytes = null, $post_max_size_bytes = null ) {
 
 	/**
+	 * Initialize the values, if none are provided by the tests.
+	 */
+	if ( is_null( $upl_max_filesize_bytes ) ) {
+		$upl_max_filesize_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
+	}
+
+	if ( is_null( $post_max_size_bytes ) ) {
+		$post_max_size_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
+	}
+
+	/**
+	 * Get an accurate max upload size.
+	 *
+	 * If one of the limits is set to 0, but the other one isn't
+	 * this value will be wrong.
+	 * PHP treats 0 values as "unlimited", so actually the limit
+	 * is the larger value in this case.
+	 *
+	 * This is handled here, to make sure the proper limit is returned.
+     *
+     */
+
+	// get the lower limit
+	$upload_size_limit_bytes = min( $upl_max_filesize_bytes, $post_max_size_bytes );
+
+	// if the limit is 0, make sure to get the correct one
+	if ( 0 ===  $upload_size_limit_bytes ) {
+		$upload_size_limit_bytes = max( $upl_max_filesize_bytes, $post_max_size_bytes );
+	}
+
+	/**
 	 * Filter the maximum upload size allowed in php.ini.
 	 *
 	 * @since 2.5.0
 	 *
 	 * @param int $size    Max upload size limit in bytes.
-	 * @param int $u_bytes Maximum upload filesize in bytes.
-	 * @param int $p_bytes Maximum size of POST data in bytes.
+	 * @param int $upl_max_filesize_bytes Maximum upload filesize in bytes.
+	 * @param int $post_max_size_bytes Maximum size of POST data in bytes.
 	 */
-	return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
+	return apply_filters( 'upload_size_limit', $upload_size_limit_bytes, $upl_max_filesize_bytes, $post_max_size_bytes );
 }
 
 /**
