forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Media: Fix
TypeError
and improve wp_exif_frac2dec()
to only retur…
…n `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. git-svn-id: https://develop.svn.wordpress.org/trunk@52269 602fd350-edb4-49c9-b593-d223f7449a82
- Loading branch information
1 parent
4ff41ed
commit 8aa625b
Showing
4 changed files
with
254 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.