File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,12 @@ public function mapRawData(array $data)
165165 break ;
166166 case self ::FOCALLENGTH :
167167 $ parts = explode ('/ ' , $ value );
168- $ value = (int ) reset ($ parts ) / (int ) end ($ parts );
168+ // Avoid division by zero if focal length is invalid
169+ if (end ($ parts ) == '0 ' ) {
170+ $ value = 0 ;
171+ } else {
172+ $ value = (int ) reset ($ parts ) / (int ) end ($ parts );
173+ }
169174 break ;
170175 case self ::XRESOLUTION :
171176 case self ::YRESOLUTION :
Original file line number Diff line number Diff line change @@ -138,6 +138,21 @@ public function testMapRawDataCorrectlyFormatsFocalLength()
138138 $ this ->assertEquals (6 , reset ($ mapped ));
139139 }
140140
141+ /**
142+ * @group mapper
143+ * @covers \PHPExif\Mapper\Native::mapRawData
144+ */
145+ public function testMapRawDataCorrectlyFormatsFocalLengthDivisionByZero ()
146+ {
147+ $ rawData = array (
148+ \PHPExif \Mapper \Native::FOCALLENGTH => '1/0 ' ,
149+ );
150+
151+ $ mapped = $ this ->mapper ->mapRawData ($ rawData );
152+
153+ $ this ->assertEquals (0 , reset ($ mapped ));
154+ }
155+
141156 /**
142157 * @group mapper
143158 * @covers \PHPExif\Mapper\Native::mapRawData
You can’t perform that action at this time.
0 commit comments