summaryrefslogtreecommitdiff
path: root/includes/MimeMagic.php
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-07-26 21:10:52 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-07-26 21:10:52 -0400
commitbe4fcbd51a4b134c7c9e3945f86295e33bbb45b6 (patch)
treee1bc6098e720429b75bd69e4566c39c7fb29aafe /includes/MimeMagic.php
parent68da4046dd3cbe1c3cccf4daa4a862594a01e80e (diff)
parentf80b2307028ed4d9231a0bd46496b241dcf4aa5c (diff)
Merge branch 'archwiki'
Diffstat (limited to 'includes/MimeMagic.php')
-rw-r--r--includes/MimeMagic.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php
index 8220e92f..9180218b 100644
--- a/includes/MimeMagic.php
+++ b/includes/MimeMagic.php
@@ -570,20 +570,30 @@ class MimeMagic {
* @param string $file
* @param mixed $ext
* @return bool|string
+ * @throws MWException
*/
private function doGuessMimeType( $file, $ext ) { // TODO: remove $ext param
// Read a chunk of the file
wfSuppressWarnings();
- // @todo FIXME: Shouldn't this be rb?
- $f = fopen( $file, 'rt' );
+ $f = fopen( $file, 'rb' );
wfRestoreWarnings();
if ( !$f ) {
return 'unknown/unknown';
}
+
+ $fsize = filesize( $file );
+ if ( $fsize === false ) {
+ return 'unknown/unknown';
+ }
+
$head = fread( $f, 1024 );
- fseek( $f, -65558, SEEK_END );
- $tail = fread( $f, 65558 ); // 65558 = maximum size of a zip EOCDR
+ $tailLength = min( 65558, $fsize ); // 65558 = maximum size of a zip EOCDR
+ if ( fseek( $f, -1 * $tailLength, SEEK_END ) === -1 ) {
+ throw new MWException(
+ "Seeking $tailLength bytes from EOF failed in " . __METHOD__ );
+ }
+ $tail = fread( $f, $tailLength );
fclose( $f );
wfDebug( __METHOD__ . ": analyzing head and tail of $file for magic numbers.\n" );