From 2692b5fc8400d04f25823e5bc00e3d4f98100a3b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 3 Nov 2010 17:05:26 -0700 Subject: [PATCH] Fix for ticket #2853: fix for some unknown MIME type error cases by adjusting the PEAR error handling temporarily around MIME_Type_Extension usage. --- classes/File.php | 13 ++++++++++--- lib/mediafile.php | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/classes/File.php b/classes/File.php index da029e39b6..c7c7658020 100644 --- a/classes/File.php +++ b/classes/File.php @@ -217,12 +217,19 @@ class File extends Memcached_DataObject static function filename($profile, $basename, $mimetype) { require_once 'MIME/Type/Extension.php'; + + // We have to temporarily disable auto handling of PEAR errors... + PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); + $mte = new MIME_Type_Extension(); - try { - $ext = $mte->getExtension($mimetype); - } catch ( Exception $e) { + $ext = $mte->getExtension($mimetype); + if (PEAR::isError($ext)) { $ext = strtolower(preg_replace('/\W/', '', $mimetype)); } + + // Restore error handling. + PEAR::staticPopErrorHandling(); + $nickname = $profile->nickname; $datestamp = strftime('%Y%m%dT%H%M%S', time()); $random = strtolower(common_confirmation_code(32)); diff --git a/lib/mediafile.php b/lib/mediafile.php index 23338cc0e1..aad3575d72 100644 --- a/lib/mediafile.php +++ b/lib/mediafile.php @@ -278,6 +278,9 @@ class MediaFile static function getUploadedFileType($f, $originalFilename=false) { require_once 'MIME/Type.php'; require_once 'MIME/Type/Extension.php'; + + // We have to disable auto handling of PEAR errors + PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $mte = new MIME_Type_Extension(); $cmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd'); @@ -330,6 +333,8 @@ class MediaFile } } if ($supported === true || in_array($filetype, $supported)) { + // Restore PEAR error handlers for our DB code... + PEAR::staticPopErrorHandling(); return $filetype; } $media = MIME_Type::getMedia($filetype); @@ -344,6 +349,8 @@ class MediaFile // TRANS: %s is the file type that was denied. $hint = sprintf(_('"%s" is not a supported file type on this server.'), $filetype); } + // Restore PEAR error handlers for our DB code... + PEAR::staticPopErrorHandling(); throw new ClientException($hint); }