<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[52269] trunk: Media: Fix `TypeError` and improve `wp_exif_frac2dec()` to only return `int` or `float`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/52269">52269</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/52269","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>hellofromTonya</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-11-29 19:34:51 +0000 (Mon, 29 Nov 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/1">#1</a> ($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 <a href="https://core.trac.wordpress.org/changeset/6313">[6313]</a>, <a href="https://core.trac.wordpress.org/changeset/9119">[9119]</a>, <a href="https://core.trac.wordpress.org/changeset/22319">[22319]</a>, <a href="https://core.trac.wordpress.org/changeset/28367">[28367]</a>, <a href="https://core.trac.wordpress.org/changeset/45611">[45611]</a>, <a href="https://core.trac.wordpress.org/changeset/47287">[47287]</a>.

Props adamsilverstein, jrf, peterwilsoncc, praem90, stevegs, tobiasbg.
Fixes <a href="https://core.trac.wordpress.org/ticket/54385">#54385</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesimagephp">trunk/src/wp-admin/includes/image.php</a></li>
<li><a href="#trunktestsphpunittestsimagefunctionsphp">trunk/tests/phpunit/tests/image/functions.php</a></li>
<li><a href="#trunktestsphpunittestsimagemetaphp">trunk/tests/phpunit/tests/image/meta.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunitdataimagessugarloafmountainjpg">trunk/tests/phpunit/data/images/sugarloaf-mountain.jpg</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesimagephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/image.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/image.php     2021-11-29 11:41:50 UTC (rev 52268)
+++ trunk/src/wp-admin/includes/image.php       2021-11-29 19:34:51 UTC (rev 52269)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -646,19 +646,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 2.5.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $str
- * @return int|float
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $str Fraction string.
+ * @return int|float Returns calculated fraction or integer 0 on invalid input.
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_exif_frac2dec( $str ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( false === strpos( $str, '/' ) ) {
-               return $str;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_scalar( $str ) || is_bool( $str ) ) {
+               return 0;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        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;
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         list( $numerator, $denominator ) = explode( '/', $str );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( ! empty( $denominator ) ) {
-               return $numerator / $denominator;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       // Both the numerator and the denominator must be numbers.
+       if ( ! is_numeric( $numerator ) || ! is_numeric( $denominator ) ) {
+               return 0;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        return $str;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       // The denominator must not be zero.
+       if ( 0 == $denominator ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
+               return 0;
+       }
+
+       return $numerator / $denominator;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -840,7 +861,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( empty( $meta['copyright'] ) && ! empty( $exif['Copyright'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $meta['copyright'] = trim( $exif['Copyright'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! empty( $exif['FNumber'] ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ! empty( $exif['FNumber'] ) && is_scalar( $exif['FNumber'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $meta['aperture'] = round( wp_exif_frac2dec( $exif['FNumber'] ), 2 );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $exif['Model'] ) ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -850,7 +871,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $meta['created_timestamp'] = wp_exif_date2ts( $exif['DateTimeDigitized'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $exif['FocalLength'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $meta['focal_length'] = (string) $exif['FocalLength'];
+                       if ( is_scalar( $exif['FocalLength'] ) ) {
+                               $meta['focal_length'] = (string) wp_exif_frac2dec( $exif['FocalLength'] );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $exif['ISOSpeedRatings'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -857,7 +881,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $meta['iso'] = trim( $meta['iso'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $exif['ExposureTime'] ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 $meta['shutter_speed'] = (string) $exif['ExposureTime'];
+                       if ( is_scalar( $exif['ExposureTime'] ) ) {
+                               $meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">                if ( ! empty( $exif['Orientation'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $meta['orientation'] = $exif['Orientation'];
</span><span class="cx" style="display: block; padding: 0 10px">Index: trunk/tests/phpunit/data/images/sugarloaf-mountain.jpg
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- trunk/tests/phpunit/data/images/sugarloaf-mountain.jpg       2021-11-29 11:41:50 UTC (rev 52268)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ trunk/tests/phpunit/data/images/sugarloaf-mountain.jpg        2021-11-29 19:34:51 UTC (rev 52269)
</ins></span></pre></div>
<a id="trunktestsphpunitdataimagessugarloafmountainjpg"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: trunk/tests/phpunit/data/images/sugarloaf-mountain.jpg</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestsimagefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/functions.php     2021-11-29 11:41:50 UTC (rev 52268)
+++ trunk/tests/phpunit/tests/image/functions.php       2021-11-29 19:34:51 UTC (rev 52269)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -700,4 +700,130 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        unlink( $temp_dir . $size['file'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * Test for wp_exif_frac2dec verified that it properly handles edge cases
+        * and always returns an int or float, or 0 for failures.
+        *
+        * @param mixed     $fraction The fraction to convert.
+        * @param int|float $expect   The expected result.
+        *
+        * @ticket 54385
+        * @dataProvider data_wp_exif_frac2dec
+        *
+        * @covers ::wp_exif_frac2dec
+        */
+       public function test_wp_exif_frac2dec( $fraction, $expect ) {
+               $this->assertSame( $expect, wp_exif_frac2dec( $fraction ) );
+       }
+
+       /**
+        * Data provider for testing `wp_exif_frac2dec()`.
+        *
+        * @return array
+        */
+       public function data_wp_exif_frac2dec() {
+               return array(
+                       'invalid input: null'              => array(
+                               'fraction' => null,
+                               'expect'   => 0,
+                       ),
+                       'invalid input: boolean true'      => array(
+                               'fraction' => null,
+                               'expect'   => 0,
+                       ),
+                       'invalid input: empty array value' => array(
+                               'fraction' => array(),
+                               'expect'   => 0,
+                       ),
+                       'input is already integer'         => array(
+                               'fraction' => 12,
+                               'expect'   => 12,
+                       ),
+                       'input is already float'           => array(
+                               'fraction' => 10.123,
+                               'expect'   => 10.123,
+                       ),
+                       'string input is not a fraction - no slash, not numeric' => array(
+                               'fraction' => '123notafraction',
+                               'expect'   => 0,
+                       ),
+                       'string input is not a fraction - no slash, numeric integer' => array(
+                               'fraction' => '48',
+                               'expect'   => 48.0,
+                       ),
+                       'string input is not a fraction - no slash, numeric integer (integer 0)' => array(
+                               'fraction' => '0',
+                               'expect'   => 0.0,
+                       ),
+                       'string input is not a fraction - no slash, octal numeric integer' => array(
+                               'fraction' => '010',
+                               'expect'   => 10.0,
+                       ),
+                       'string input is not a fraction - no slash, numeric float (float 0)' => array(
+                               'fraction' => '0.0',
+                               'expect'   => 0.0,
+                       ),
+                       'string input is not a fraction - no slash, numeric float (typical fnumber)' => array(
+                               'fraction' => '4.8',
+                               'expect'   => 4.8,
+                       ),
+                       'string input is not a fraction - more than 1 slash with text' => array(
+                               'fraction' => 'path/to/file',
+                               'expect'   => 0,
+                       ),
+                       'string input is not a fraction - more than 1 slash with numbers' => array(
+                               'fraction' => '1/2/3',
+                               'expect'   => 0,
+                       ),
+                       'string input is not a fraction - only a slash' => array(
+                               'fraction' => '/',
+                               'expect'   => 0,
+                       ),
+                       'string input is not a fraction - only slashes' => array(
+                               'fraction' => '///',
+                               'expect'   => 0,
+                       ),
+                       'string input is not a fraction - left/right is not numeric' => array(
+                               'fraction' => 'path/to',
+                               'expect'   => 0,
+                       ),
+                       'string input is not a fraction - left is not numeric' => array(
+                               'fraction' => 'path/10',
+                               'expect'   => 0,
+                       ),
+                       'string input is not a fraction - right is not numeric' => array(
+                               'fraction' => '0/abc',
+                               'expect'   => 0,
+                       ),
+                       'division by zero is prevented 1'  => array(
+                               'fraction' => '0/0',
+                               'expect'   => 0,
+                       ),
+                       'division by zero is prevented 2'  => array(
+                               'fraction' => '100/0.0',
+                               'expect'   => 0,
+                       ),
+                       'typical focal length'             => array(
+                               'fraction' => '37 mm',
+                               'expect'   => 0,
+                       ),
+                       'typical exposure time'            => array(
+                               'fraction' => '1/350',
+                               'expect'   => 0.002857142857142857,
+                       ),
+                       'valid fraction 1'                 => array(
+                               'fraction' => '50/100',
+                               'expect'   => 0.5,
+                       ),
+                       'valid fraction 2'                 => array(
+                               'fraction' => '25/100',
+                               'expect'   => .25,
+                       ),
+                       'valid fraction 3'                 => array(
+                               'fraction' => '4/2',
+                               'expect'   => 2,
+                       ),
+               );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsimagemetaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/meta.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/meta.php  2021-11-29 11:41:50 UTC (rev 52268)
+++ trunk/tests/phpunit/tests/image/meta.php    2021-11-29 19:34:51 UTC (rev 52269)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -32,16 +32,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Exif from a Nikon D70.
</span><span class="cx" style="display: block; padding: 0 10px">                $out = wp_read_image_metadata( DIR_TESTDATA . '/images/2004-07-22-DSC_0008.jpg' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 6.3, $out['aperture'] );
-               $this->assertSame( '', $out['credit'] );
-               $this->assertSame( 'NIKON D70', $out['camera'] );
-               $this->assertSame( '', $out['caption'] );
-               $this->assertEquals( strtotime( '2004-07-22 17:14:59' ), $out['created_timestamp'] );
-               $this->assertSame( '', $out['copyright'] );
-               $this->assertEquals( 27, $out['focal_length'] );
-               $this->assertEquals( 400, $out['iso'] );
-               $this->assertEquals( 1 / 40, $out['shutter_speed'] );
-               $this->assertSame( '', $out['title'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 6.3, $out['aperture'], 'Aperture value not equivalent' );
+               $this->assertSame( '', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( 'NIKON D70', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( '', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( strtotime( '2004-07-22 17:14:59' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
+               $this->assertEquals( 27, $out['focal_length'], 'Focal length value not equivalent' );
+               $this->assertEquals( 400, $out['iso'], 'Iso value not equivalent' );
+               $this->assertEquals( 1 / 40, $out['shutter_speed'], 'Shutter speed value not equivalent' );
+               $this->assertSame( '', $out['title'], 'Title value not the same' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_exif_d70_mf() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -48,16 +48,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Exif from a Nikon D70 - manual focus lens, so some data is unavailable.
</span><span class="cx" style="display: block; padding: 0 10px">                $out = wp_read_image_metadata( DIR_TESTDATA . '/images/2007-06-17DSC_4173.JPG' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertSame( '0', $out['aperture'] );
-               $this->assertSame( '', $out['credit'] );
-               $this->assertSame( 'NIKON D70', $out['camera'] );
-               $this->assertSame( '', $out['caption'] );
-               $this->assertEquals( strtotime( '2007-06-17 21:18:00' ), $out['created_timestamp'] );
-               $this->assertSame( '', $out['copyright'] );
-               $this->assertEquals( 0, $out['focal_length'] );
-               $this->assertEquals( 0, $out['iso'] ); // Interesting - a Nikon bug?
-               $this->assertEquals( 1 / 500, $out['shutter_speed'] );
-               $this->assertSame( '', $out['title'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( '0', $out['aperture'], 'Aperture value not the same' );
+               $this->assertSame( '', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( 'NIKON D70', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( '', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( strtotime( '2007-06-17 21:18:00' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
+               $this->assertEquals( 0, $out['focal_length'], 'Focal length value not equivalent' );
+               $this->assertEquals( 0, $out['iso'], 'Iso value not equivalent' ); // Interesting - a Nikon bug?
+               $this->assertEquals( 1 / 500, $out['shutter_speed'], 'Shutter speed value not equivalent' );
+               $this->assertSame( '', $out['title'], 'Title value not the same' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 // $this->assertSame( array( 'Flowers' ), $out['keywords'] );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -65,16 +65,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Exif from a Nikon D70 with IPTC data added later.
</span><span class="cx" style="display: block; padding: 0 10px">                $out = wp_read_image_metadata( DIR_TESTDATA . '/images/2004-07-22-DSC_0007.jpg' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 6.3, $out['aperture'] );
-               $this->assertSame( 'IPTC Creator', $out['credit'] );
-               $this->assertSame( 'NIKON D70', $out['camera'] );
-               $this->assertSame( 'IPTC Caption', $out['caption'] );
-               $this->assertEquals( strtotime( '2004-07-22 17:14:35' ), $out['created_timestamp'] );
-               $this->assertSame( 'IPTC Copyright', $out['copyright'] );
-               $this->assertEquals( 18, $out['focal_length'] );
-               $this->assertEquals( 200, $out['iso'] );
-               $this->assertEquals( 1 / 25, $out['shutter_speed'] );
-               $this->assertSame( 'IPTC Headline', $out['title'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 6.3, $out['aperture'], 'Aperture value not equivalent' );
+               $this->assertSame( 'IPTC Creator', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( 'NIKON D70', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( 'IPTC Caption', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( strtotime( '2004-07-22 17:14:35' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( 'IPTC Copyright', $out['copyright'], 'Copyright value not the same' );
+               $this->assertEquals( 18, $out['focal_length'], 'Focal length value not equivalent' );
+               $this->assertEquals( 200, $out['iso'], 'Iso value not equivalent' );
+               $this->assertEquals( 1 / 25, $out['shutter_speed'], 'Shutter speed value not equivalent' );
+               $this->assertSame( 'IPTC Headline', $out['title'], 'Title value not the same' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_exif_fuji() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -81,17 +81,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Exif from a Fuji FinePix S5600 (thanks Mark).
</span><span class="cx" style="display: block; padding: 0 10px">                $out = wp_read_image_metadata( DIR_TESTDATA . '/images/a2-small.jpg' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 4.5, $out['aperture'] );
-               $this->assertSame( '', $out['credit'] );
-               $this->assertSame( 'FinePix S5600', $out['camera'] );
-               $this->assertSame( '', $out['caption'] );
-               $this->assertEquals( strtotime( '2007-09-03 10:17:03' ), $out['created_timestamp'] );
-               $this->assertSame( '', $out['copyright'] );
-               $this->assertEquals( 6.3, $out['focal_length'] );
-               $this->assertEquals( 64, $out['iso'] );
-               $this->assertEquals( 1 / 320, $out['shutter_speed'] );
-               $this->assertSame( '', $out['title'] );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 4.5, $out['aperture'], 'Aperture value not equivalent' );
+               $this->assertSame( '', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( 'FinePix S5600', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( '', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( strtotime( '2007-09-03 10:17:03' ), $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
+               $this->assertEquals( 6.3, $out['focal_length'], 'Focal length value not equivalent' );
+               $this->assertEquals( 64, $out['iso'], 'Iso value not equivalent' );
+               $this->assertEquals( 1 / 320, $out['shutter_speed'], 'Shutter speed value not equivalent' );
+               $this->assertSame( '', $out['title'], 'Title value not the same' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -102,16 +101,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // This triggers a warning mesage when reading the Exif block.
</span><span class="cx" style="display: block; padding: 0 10px">                $out = wp_read_image_metadata( DIR_TESTDATA . '/images/waffles.jpg' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 0, $out['aperture'] );
-               $this->assertSame( '', $out['credit'] );
-               $this->assertSame( '', $out['camera'] );
-               $this->assertSame( '', $out['caption'] );
-               $this->assertEquals( 0, $out['created_timestamp'] );
-               $this->assertSame( '', $out['copyright'] );
-               $this->assertEquals( 0, $out['focal_length'] );
-               $this->assertEquals( 0, $out['iso'] );
-               $this->assertEquals( 0, $out['shutter_speed'] );
-               $this->assertSame( '', $out['title'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 0, $out['aperture'], 'Aperture value not equivalent' );
+               $this->assertSame( '', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( '', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( '', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( 0, $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
+               $this->assertEquals( 0, $out['focal_length'], 'Focal length value not equivalent' );
+               $this->assertEquals( 0, $out['iso'], 'Iso value not equivalent' );
+               $this->assertEquals( 0, $out['shutter_speed'], 'Shutter speed value not equivalent' );
+               $this->assertSame( '', $out['title'], 'Title value not the same' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_exif_no_data() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -118,16 +117,16 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // No Exif data in this image (from burningwell.org).
</span><span class="cx" style="display: block; padding: 0 10px">                $out = wp_read_image_metadata( DIR_TESTDATA . '/images/canola.jpg' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertEquals( 0, $out['aperture'] );
-               $this->assertSame( '', $out['credit'] );
-               $this->assertSame( '', $out['camera'] );
-               $this->assertSame( '', $out['caption'] );
-               $this->assertEquals( 0, $out['created_timestamp'] );
-               $this->assertSame( '', $out['copyright'] );
-               $this->assertEquals( 0, $out['focal_length'] );
-               $this->assertEquals( 0, $out['iso'] );
-               $this->assertEquals( 0, $out['shutter_speed'] );
-               $this->assertSame( '', $out['title'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertEquals( 0, $out['aperture'], 'Aperture value not equivalent' );
+               $this->assertSame( '', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( '', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( '', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( 0, $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
+               $this->assertEquals( 0, $out['focal_length'], 'Focal length value not equivalent' );
+               $this->assertEquals( 0, $out['iso'], 'Iso value not equivalent' );
+               $this->assertEquals( 0, $out['shutter_speed'], 'Shutter speed value not equivalent' );
+               $this->assertSame( '', $out['title'], 'Title value not the same' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -155,18 +154,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function test_exif_keywords() {
</span><span class="cx" style="display: block; padding: 0 10px">                $out = wp_read_image_metadata( DIR_TESTDATA . '/images/33772.jpg' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertSame( '8', $out['aperture'] );
-               $this->assertSame( 'Photoshop Author', $out['credit'] );
-               $this->assertSame( 'DMC-LX2', $out['camera'] );
-               $this->assertSame( 'Photoshop Description', $out['caption'] );
-               $this->assertEquals( 1306315327, $out['created_timestamp'] );
-               $this->assertSame( 'Photoshop Copyrright Notice', $out['copyright'] );
-               $this->assertSame( '6.3', $out['focal_length'] );
-               $this->assertSame( '100', $out['iso'] );
-               $this->assertSame( '0.0025', $out['shutter_speed'] );
-               $this->assertSame( 'Photoshop Document Ttitle', $out['title'] );
-               $this->assertEquals( 1, $out['orientation'] );
-               $this->assertSame( array( 'beach', 'baywatch', 'LA', 'sunset' ), $out['keywords'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $this->assertSame( '8', $out['aperture'], 'Aperture value not the same' );
+               $this->assertSame( 'Photoshop Author', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( 'DMC-LX2', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( 'Photoshop Description', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( 1306315327, $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( 'Photoshop Copyrright Notice', $out['copyright'], 'Copyright value not the same' );
+               $this->assertSame( '6.3', $out['focal_length'], 'Focal length value not the same' );
+               $this->assertSame( '100', $out['iso'], 'Iso value not the same' );
+               $this->assertSame( '0.0025', $out['shutter_speed'], 'Shutter speed value not the same' );
+               $this->assertSame( 'Photoshop Document Ttitle', $out['title'], 'Title value not the same' );
+               $this->assertEquals( 1, $out['orientation'], 'Orientation value not equivalent' );
+               $this->assertSame( array( 'beach', 'baywatch', 'LA', 'sunset' ), $out['keywords'], 'Keywords not the same' );
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -239,4 +238,23 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        ),
</span><span class="cx" style="display: block; padding: 0 10px">                );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @ticket 54385
+        */
+       public function test_exif_unexpected_data() {
+               // Unexpected Exif data: FNumber is "0/0", aperture should be 0.
+               $out = wp_read_image_metadata( DIR_TESTDATA . '/images/sugarloaf-mountain.jpg' );
+
+               $this->assertEquals( 0, $out['aperture'], 'Aperture value not equivalent' );
+               $this->assertSame( '', $out['credit'], 'Credit value not the same' );
+               $this->assertSame( 'X-T1', $out['camera'], 'Camera value not the same' );
+               $this->assertSame( '', $out['caption'], 'Caption value not the same' );
+               $this->assertEquals( 0, $out['created_timestamp'], 'Timestamp value not equivalent' );
+               $this->assertSame( '', $out['copyright'], 'Copyright value not the same' );
+               $this->assertEquals( 50, $out['focal_length'], 'Focal length value not equivalent' );
+               $this->assertEquals( 200, $out['iso'], 'Iso value not equivalent' );
+               $this->assertEquals( 2, $out['shutter_speed'], 'Shutter speed value not equivalent' );
+               $this->assertSame( 'Sugarloaf Panorama', $out['title'], 'Title value not the same' );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>