(Follow-up r86169) Needed supress warnings around iconv
authorBrian Wolff <bawolff@users.mediawiki.org>
Sat, 16 Apr 2011 15:53:08 +0000 (15:53 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Sat, 16 Apr 2011 15:53:08 +0000 (15:53 +0000)
Also make it try to detect if a jpeg file comment has textual data, or is random binary stuff.

includes/media/Exif.php
includes/media/IPTC.php
includes/media/JpegMetadataExtractor.php
includes/media/XMP.php

index 90a574b..adaec1d 100644 (file)
@@ -435,13 +435,17 @@ class Exif {
                        // This could possibly check to see if iconv is really installed
                        // or if we're using the compatibility wrapper in globalFunctions.php
                        if ($charset) {
+                               wfSuppressWarnings();
                                $val = iconv($charset, 'UTF-8//IGNORE', $val);
+                               wfRestoreWarnings();
                        } else {
                                // if valid utf-8, assume that, otherwise assume windows-1252
                                $valCopy = $val;
                                UtfNormal::quickIsNFCVerify( $valCopy ); //validates $valCopy.
                                if ( $valCopy !== $val ) {
+                                       wfSuppressWarnings();
                                        $val = iconv('Windows-1252', 'UTF-8//IGNORE', $val);
+                                       wfRestoreWarnings();
                                }
                        }
                        
index 896aa36..83aaf3e 100644 (file)
@@ -418,7 +418,9 @@ class IPTC {
        */
        private static function convIPTCHelper ( $data, $charset ) {
                if ( $charset ) {
+                       wfSuppressWarnings();
                        $data = iconv($charset, "UTF-8//IGNORE", $data);
+                       wfRestoreWarnings();
                        if ($data === false) {
                                $data = "";
                                wfDebugLog('iptc', __METHOD__ . " Error converting iptc data charset $charset to utf-8");
index d8433fa..fec7045 100644 (file)
@@ -56,14 +56,22 @@ class JpegMetadataExtractor {
                                // First see if valid utf-8,
                                // if not try to convert it to windows-1252.
                                $com = $oldCom = trim( self::jpegExtractMarker( $fh ) );
-
                                UtfNormal::quickIsNFCVerify( $com );
                                // turns $com to valid utf-8.
                                // thus if no change, its utf-8, otherwise its something else.
                                if ( $com !== $oldCom ) {
-                                       $oldCom = iconv( 'windows-1252', 'UTF-8//IGNORE', $oldCom );
+                                       wfSuppressWarnings();
+                                       $com = $oldCom = iconv( 'windows-1252', 'UTF-8//IGNORE', $oldCom );
+                                       wfRestoreWarnings();
+                               }
+                               // Try it again, if its still not a valid string, then probably
+                               // binary junk or some really weird encoding, so don't extract.
+                               UtfNormal::quickIsNFCVerify( $com );
+                               if ( $com === $oldCom ) {
+                                       $segments["COM"][] = $oldCom;
+                               } else {
+                                       wfDebug( __METHOD__ . ' Ignoring JPEG comment as is garbage.' );
                                }
-                               $segments["COM"][] = $oldCom;
 
                        } elseif ( $buffer === "\xE1" && $showXMP ) {
                                // APP1 section (Exif, XMP, and XMP extended)
index dc56e80..1b00119 100644 (file)
@@ -260,7 +260,9 @@ class XMPReader {
                        }
                        if ( $this->charset !== 'UTF-8' ) {
                                //don't convert if already utf-8
+                               wfSuppressWarnings();
                                $content = iconv( $this->charset, 'UTF-8//IGNORE', $content );
+                               wfRestoreWarnings();
                        }
 
                        $ok = xml_parse( $this->xmlParser, $content, $allOfIt );