One of the skip-over loops was missing an feof() check and could
cause infinite loops.
Includes test file created by truncating a tiny tiny .jpeg at
the right place...
With the fix, it doesn't loop but dies on an exception, which
is good!
Bug: T184048
Change-Id: Ica13d6b68c3c12f7ce414edd081bf0886714e465
// this is just a sanity check
throw new MWException( 'Too many jpeg segments. Aborting' );
}
- while ( $buffer !== "\xFF" ) {
+ while ( $buffer !== "\xFF" && !feof( $fh ) ) {
// In theory JPEG files are not allowed to contain anything between the sections,
// but in practice they sometimes do. It's customary to ignore the garbage data.
$buffer = fread( $fh, 1 );
$expected = 'BE';
$this->assertEquals( $expected, $res['byteOrder'] );
}
+
+ public function testInfiniteRead() {
+ // Should get past infinite loop and throw in wfUnpack()
+ $this->setExpectedException( 'MWException' );
+ $res = JpegMetadataExtractor::segmentSplitter( $this->filePath . 'jpeg-xmp-loop.jpg' );
+ }
}