[wp-trac] [WordPress Trac] #54385: Fatal error uploading media on PHP8

WordPress Trac noreply at wordpress.org
Mon Nov 29 19:35:06 UTC 2021


#54385: Fatal error uploading media on PHP8
-------------------------------------------------+-------------------------
 Reporter:  stevegs                              |       Owner:
                                                 |  hellofromTonya
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  5.9
Component:  Media                                |     Version:  2.5
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  php8 has-patch needs-dev-note has-   |     Focuses:
  unit-tests commit                              |
-------------------------------------------------+-------------------------
Changes (by hellofromTonya):

 * status:  reviewing => closed
 * resolution:   => fixed


Comment:

 In [changeset:"52269" 52269]:
 {{{
 #!CommitTicketReference repository="" revision="52269"
 Media: Fix `TypeError` and improve `wp_exif_frac2dec()` to only return
 `int` or `float`.

 For certain images, `wp_exif_frac2dec()` unexpectedly returned a string
 instead of `int` or `float`. This can occur when an image is missing meta
 and calls the function with `'0/0'`. For those images, a fatal error was
 thrown on PHP 8.0+:

 {{{
 TypeError: round(): Argument #1 ($num) must be of type int|float, string
 given
 }}}

 Upon deeper review, inconsistent and unexpected results were returned from
 different types of input values passed to the function.

 Changes are:

 * Maintains backwards-compatibility for valid input values.
 * Fixes handling of invalid input values by bailing out to return the
 documented type of `int|float` by returning `0`.
 * Improves the fractional conditional check.
 * Improves the calculated fraction handling to ensure (a) the numerator
 and denominator are both numeric and (b) the denominator is not equal to
 zero.
 * Safeguards the behavior via tests for all possible ways code could flow
 through the function.
 * Safeguards the backwards-compatibility of the `wp_read_image_metadata()`
 by adding some defensive coding around the calls to the
 `wp_exif_frac2dec()` function.

 These changes fix the fatal error and make the function more secure,
 stable, and predictable while maintaining backwards-compatibility for
 valid input values.

 Follow-up to [6313], [9119], [22319], [28367], [45611], [47287].

 Props adamsilverstein, jrf, peterwilsoncc, praem90, stevegs, tobiasbg.
 Fixes #54385.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54385#comment:47>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list