From 84148848f98a336c0b2a47a8a1e808f936432519 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sat, 16 Apr 2011 15:53:08 +0000 Subject: [PATCH] (Follow-up r86169) Needed supress warnings around iconv Also make it try to detect if a jpeg file comment has textual data, or is random binary stuff. --- includes/media/Exif.php | 4 ++++ includes/media/IPTC.php | 2 ++ includes/media/JpegMetadataExtractor.php | 14 +++++++++++--- includes/media/XMP.php | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/includes/media/Exif.php b/includes/media/Exif.php index 90a574b2e1..adaec1d1b2 100644 --- a/includes/media/Exif.php +++ b/includes/media/Exif.php @@ -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(); } } diff --git a/includes/media/IPTC.php b/includes/media/IPTC.php index 896aa36131..83aaf3ed14 100644 --- a/includes/media/IPTC.php +++ b/includes/media/IPTC.php @@ -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"); diff --git a/includes/media/JpegMetadataExtractor.php b/includes/media/JpegMetadataExtractor.php index d8433fadee..fec70450fd 100644 --- a/includes/media/JpegMetadataExtractor.php +++ b/includes/media/JpegMetadataExtractor.php @@ -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) diff --git a/includes/media/XMP.php b/includes/media/XMP.php index dc56e802ee..1b001191f1 100644 --- a/includes/media/XMP.php +++ b/includes/media/XMP.php @@ -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 ); -- 2.20.1