ZipDirectoryReader: Don't try to parse zero-length files
authorBartosz Dziewoński <matma.rex@gmail.com>
Thu, 24 Mar 2016 09:14:03 +0000 (10:14 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Thu, 24 Mar 2016 09:15:10 +0000 (10:15 +0100)
With the current code, 'zip-bad' would be returned (eventually). I think
'zip-wrong-format' is a more correct response. This prevents weird errors
when trying to upload such a file (and results in saner errors instead).

Change-Id: Ic2c010f318d98df4783da1cf5126e8dd88aa9014

includes/utils/ZipDirectoryReader.php

index 44815b4..516e9ae 100644 (file)
@@ -215,6 +215,10 @@ class ZipDirectoryReader {
                        $startPos = 0;
                }
 
+               if ( $this->getFileLength() === 0 ) {
+                       $this->error( 'zip-wrong-format', "The file is empty." );
+               }
+
                $block = $this->getBlock( $startPos );
                $sigPos = strrpos( $block, "PK\x05\x06" );
                if ( $sigPos === false ) {