Update suppressWarning()/restoreWarning() calls
[lhc/web/wiklou.git] / includes / media / JpegMetadataExtractor.php
index 9ad4097..229a891 100644 (file)
@@ -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 );
@@ -93,7 +94,6 @@ class JpegMetadataExtractor {
                                $buffer = fread( $fh, 1 );
                        }
                        if ( $buffer === "\xFE" ) {
-
                                // COM section -- file comment
                                // First see if valid utf-8,
                                // if not try to convert it to windows-1252.
@@ -102,9 +102,9 @@ class JpegMetadataExtractor {
                                // turns $com to valid utf-8.
                                // thus if no change, its utf-8, otherwise its something else.
                                if ( $com !== $oldCom ) {
-                                       MediaWiki\suppressWarnings();
+                                       Wikimedia\suppressWarnings();
                                        $com = $oldCom = iconv( 'windows-1252', 'UTF-8//IGNORE', $oldCom );
-                                       MediaWiki\restoreWarnings();
+                                       Wikimedia\restoreWarnings();
                                }
                                // Try it again, if its still not a valid string, then probably
                                // binary junk or some really weird encoding, so don't extract.