Changeset 52269 for trunk/src/wp-admin/includes/image.php
- Timestamp:
- 11/29/2021 07:34:51 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/image.php
r51166 r52269 647 647 * @since 2.5.0 648 648 * 649 * @param string $str 650 * @return int|float 649 * @param string $str Fraction string. 650 * @return int|float Returns calculated fraction or integer 0 on invalid input. 651 651 */ 652 652 function wp_exif_frac2dec( $str ) { 653 if ( false === strpos( $str, '/' ) ) { 654 return $str; 653 if ( ! is_scalar( $str ) || is_bool( $str ) ) { 654 return 0; 655 } 656 657 if ( ! is_string( $str ) ) { 658 return $str; // This can only be an integer or float, so this is fine. 659 } 660 661 // Fractions passed as a string must contain a single `/`. 662 if ( substr_count( $str, '/' ) !== 1 ) { 663 if ( is_numeric( $str ) ) { 664 return (float) $str; 665 } 666 667 return 0; 655 668 } 656 669 657 670 list( $numerator, $denominator ) = explode( '/', $str ); 658 if ( ! empty( $denominator ) ) { 659 return $numerator / $denominator; 660 } 661 return $str; 671 672 // Both the numerator and the denominator must be numbers. 673 if ( ! is_numeric( $numerator ) || ! is_numeric( $denominator ) ) { 674 return 0; 675 } 676 677 // The denominator must not be zero. 678 if ( 0 == $denominator ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison. 679 return 0; 680 } 681 682 return $numerator / $denominator; 662 683 } 663 684 … … 841 862 $meta['copyright'] = trim( $exif['Copyright'] ); 842 863 } 843 if ( ! empty( $exif['FNumber'] ) ) {864 if ( ! empty( $exif['FNumber'] ) && is_scalar( $exif['FNumber'] ) ) { 844 865 $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 ); 845 866 } … … 851 872 } 852 873 if ( ! empty( $exif['FocalLength'] ) ) { 853 $meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] ); 874 $meta['focal_length'] = (string) $exif['FocalLength']; 875 if ( is_scalar( $exif['FocalLength'] ) ) { 876 $meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] ); 877 } 854 878 } 855 879 if ( ! empty( $exif['ISOSpeedRatings'] ) ) { … … 858 882 } 859 883 if ( ! empty( $exif['ExposureTime'] ) ) { 860 $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] ); 884 $meta['shutter_speed'] = (string) $exif['ExposureTime']; 885 if ( is_scalar( $exif['ExposureTime'] ) ) { 886 $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] ); 887 } 861 888 } 862 889 if ( ! empty( $exif['Orientation'] ) ) {
Note: See TracChangeset
for help on using the changeset viewer.