diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index d8d5d5b34b..9cab18a22a 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -646,19 +646,40 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { * * @since 2.5.0 * - * @param string $str - * @return int|float + * @param string $str Fraction string. + * @return int|float Returns calculated fraction or integer 0 on invalid input. */ function wp_exif_frac2dec( $str ) { - if ( false === strpos( $str, '/' ) ) { - return $str; + if ( ! is_scalar( $str ) || is_bool( $str ) ) { + return 0; + } + + if ( ! is_string( $str ) ) { + return $str; // This can only be an integer or float, so this is fine. + } + + // Fractions passed as a string must contain a single `/`. + if ( substr_count( $str, '/' ) !== 1 ) { + if ( is_numeric( $str ) ) { + return (float) $str; + } + + return 0; } list( $numerator, $denominator ) = explode( '/', $str ); - if ( ! empty( $denominator ) ) { - return $numerator / $denominator; + + // Both the numerator and the denominator must be numbers. + if ( ! is_numeric( $numerator ) || ! is_numeric( $denominator ) ) { + return 0; } - return $str; + + // The denominator must not be zero. + if ( 0 == $denominator ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison. + return 0; + } + + return $numerator / $denominator; } /** @@ -840,7 +861,7 @@ function wp_read_image_metadata( $file ) { if ( empty( $meta['copyright'] ) && ! empty( $exif['Copyright'] ) ) { $meta['copyright'] = trim( $exif['Copyright'] ); } - if ( ! empty( $exif['FNumber'] ) ) { + if ( ! empty( $exif['FNumber'] ) && is_scalar( $exif['FNumber'] ) ) { $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 ); } if ( ! empty( $exif['Model'] ) ) { @@ -850,14 +871,20 @@ function wp_read_image_metadata( $file ) { $meta['created_timestamp'] = wp_exif_date2ts( $exif['DateTimeDigitized'] ); } if ( ! empty( $exif['FocalLength'] ) ) { - $meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] ); + $meta['focal_length'] = (string) $exif['FocalLength']; + if ( is_scalar( $exif['FocalLength'] ) ) { + $meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] ); + } } if ( ! empty( $exif['ISOSpeedRatings'] ) ) { $meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings']; $meta['iso'] = trim( $meta['iso'] ); } if ( ! empty( $exif['ExposureTime'] ) ) { - $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] ); + $meta['shutter_speed'] = (string) $exif['ExposureTime']; + if ( is_scalar( $exif['ExposureTime'] ) ) { + $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] ); + } } if ( ! empty( $exif['Orientation'] ) ) { $meta['orientation'] = $exif['Orientation']; diff --git a/wp-includes/version.php b/wp-includes/version.php index ff937b318c..6ae4b83fc0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52268'; +$wp_version = '5.9-alpha-52269'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.