X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fmedia%2FJpegMetadataExtractorTest.php;h=c943cef906108ac8837abe7e9afebb0cdf6dd59f;hp=7c977d5a45bcfda5d14529282287a8a611f00616;hb=f17f841a9dfa1bee3f8ed47a09f06d1226452573;hpb=6b1a173f07f1a04188735f4688ce6335da14c3b7 diff --git a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php index 7c977d5a45..c943cef906 100644 --- a/tests/phpunit/includes/media/JpegMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/JpegMetadataExtractorTest.php @@ -29,21 +29,21 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase { */ public function testUtf8Comment( $file ) { $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . $file ); - $this->assertEquals( array( 'UTF-8 JPEG Comment — ¼' ), $res['COM'] ); + $this->assertEquals( [ 'UTF-8 JPEG Comment — ¼' ], $res['COM'] ); } public static function provideUtf8Comment() { - return array( - array( 'jpeg-comment-utf.jpg' ), - array( 'jpeg-padding-even.jpg' ), - array( 'jpeg-padding-odd.jpg' ), - ); + return [ + [ 'jpeg-comment-utf.jpg' ], + [ 'jpeg-padding-even.jpg' ], + [ 'jpeg-padding-odd.jpg' ], + ]; } /** The file is iso-8859-1, but it should get auto converted */ public function testIso88591Comment() { $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-iso8859-1.jpg' ); - $this->assertEquals( array( 'ISO-8859-1 JPEG Comment - ¼' ), $res['COM'] ); + $this->assertEquals( [ 'ISO-8859-1 JPEG Comment - ¼' ], $res['COM'] ); } /** Comment values that are non-textual (random binary junk) should not be shown. @@ -60,7 +60,7 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase { */ public function testMultipleComment() { $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-comment-multiple.jpg' ); - $this->assertEquals( array( 'foo', 'bar' ), $res['COM'] ); + $this->assertEquals( [ 'foo', 'bar' ], $res['COM'] ); } public function testXMPExtraction() { @@ -108,4 +108,21 @@ class JpegMetadataExtractorTest extends MediaWikiTestCase { $expected = 'BE'; $this->assertEquals( $expected, $res['byteOrder'] ); } + + public function testInfiniteRead() { + // test file truncated right after a segment, which previously + // caused an infinite loop looking for the next segment byte. + // Should get past infinite loop and throw in wfUnpack() + $this->setExpectedException( 'MWException' ); + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-segment-loop1.jpg' ); + } + + public function testInfiniteRead2() { + // test file truncated after a segment's marker and size, which + // would cause a seek past end of file. Seek past end of file + // doesn't actually fail, but prevents further reading and was + // devolving into the previous case (testInfiniteRead). + $this->setExpectedException( 'MWException' ); + $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-segment-loop2.jpg' ); + } }