Merge "FauxRequest: don’t override getValues()"
[lhc/web/wiklou.git] / includes / libs / mime / MimeAnalyzer.php
index 42146f4..6fca043 100644 (file)
@@ -21,6 +21,7 @@
  */
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
 
 /**
  * Implements functions related to MIME types such as detection and mapping to file extension
@@ -199,7 +200,7 @@ EOT;
                $this->detectCallback = $params['detectCallback'] ?? null;
                $this->guessCallback = $params['guessCallback'] ?? null;
                $this->extCallback = $params['extCallback'] ?? null;
-               $this->logger = $params['logger'] ?? new \Psr\Log\NullLogger();
+               $this->logger = $params['logger'] ?? new NullLogger();
 
                $this->loadFiles();
        }
@@ -805,10 +806,10 @@ EOT;
 
                // Check for ZIP variants (before getimagesize)
                $eocdrPos = strpos( $tail, "PK\x05\x06" );
-               if ( $eocdrPos !== false ) {
+               if ( $eocdrPos !== false && $eocdrPos <= strlen( $tail ) - 22 ) {
                        $this->logger->info( __METHOD__ . ": ZIP signature present in $file\n" );
                        // Check if it really is a ZIP file, make sure the EOCDR is at the end (T40432)
-                       $commentLength = unpack( "n", substr( $tail, $eocdrPos + 20 ) )[0];
+                       $commentLength = unpack( "n", substr( $tail, $eocdrPos + 20 ) )[1];
                        if ( $eocdrPos + 22 + $commentLength !== strlen( $tail ) ) {
                                $this->logger->info( __METHOD__ . ": ZIP EOCDR not at end. Not a ZIP file." );
                        } else {
@@ -1088,7 +1089,7 @@ EOT;
 
                // Special code for ogg - detect if it's video (theora),
                // else label it as sound.
-               if ( $mime == 'application/ogg' && file_exists( $path ) ) {
+               if ( $mime == 'application/ogg' && is_string( $path ) && file_exists( $path ) ) {
                        // Read a chunk of the file
                        $f = fopen( $path, "rt" );
                        if ( !$f ) {