From: Bartosz DziewoƄski Date: Wed, 19 Oct 2016 06:20:23 +0000 (-0700) Subject: JpegMetadataExtractor: Don't fail when garbage bytes are present between JPEG sections X-Git-Tag: 1.31.0-rc.0~5067^2 X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28?a=commitdiff_plain;h=5506a8d43ddc4eb35ab566f63fbba074f85da10e;p=lhc%2Fweb%2Fwiklou.git JpegMetadataExtractor: Don't fail when garbage bytes are present between JPEG sections 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. Bug: T148606 Change-Id: I98f2609644bcd8bfd7c1679afc6e7af83e228685 --- diff --git a/includes/media/JpegMetadataExtractor.php b/includes/media/JpegMetadataExtractor.php index 9ad40977bc..67c957adac 100644 --- a/includes/media/JpegMetadataExtractor.php +++ b/includes/media/JpegMetadataExtractor.php @@ -82,9 +82,10 @@ class JpegMetadataExtractor { // this is just a sanity check throw new MWException( 'Too many jpeg segments. Aborting' ); } - if ( $buffer !== "\xFF" ) { - throw new MWException( "Error reading jpeg file marker. " . - "Expected 0xFF but got " . bin2hex( $buffer ) ); + while ( $buffer !== "\xFF" ) { + // 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 ); } $buffer = fread( $fh, 1 );