WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#24558 closed defect (bug) (duplicate)

wp_max_upload_size does not correctly interpret post_max_size = 0

Reported by: maaarghk Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords:
Focuses: Cc:
PR Number:

Description (last modified by ocean90)

if ini_get( 'post_max_size' ) returns 0 then there the post size is unlimited. WP treats this as if the max size is 0 bytes. a quick fix is in wp-includes/media.php : update function wp_max_upload_size() as follows:

       $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
       $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
       ($p_bytes == 0) ? $p_bytes = $u_bytes : $p_bytes = $p_bytes;
       $bytes   = apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
       return $bytes;

This is dirty code but does the job - I feel the proper place for the fix is behind the upload_size_limit filter but I don't know enough about WP to provide a proper patch. However, by setting post_max_size=0 and testing this code you should be able to reproduce the bug easily.

Change History (4)

#1 @ocean90
6 years ago

  • Description modified (diff)

#2 @adamsilverstein
6 years ago

  • Keywords needs-patch added

Thanks for the bug report maaarghk! I verified this issue, and also noticed that setting upload_max_filesize to 0 has the same result so it would be worth checking that value as well. If both are zero the proposed patch will fail.

Since the underlying PHP upload limit will be unlimited as intended by setting wp_max_upload_size to 0, the real issue is the number WordPress displays in the media uploader: Maximum upload file size: 0KB. (and how it treats that limit). This function is used in just a few places in core, looking at those would be a good start towards resolving the issue.

Maaarghk - this would be a great opportunity to try your hand at contributing a patch to fix the issue.

This ticket was mentioned in IRC in #wordpress-dev by adamsilverstein. View the logs.


6 years ago

#4 @SergeyBiryukov
6 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #23895.

Note: See TracTickets for help on using tickets.