From 5506a8d43ddc4eb35ab566f63fbba074f85da10e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Tue, 18 Oct 2016 23:20:23 -0700 Subject: [PATCH] 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 --- includes/media/JpegMetadataExtractor.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 ); -- 2.20.1