public static function checkWhetherArchiveIsBomb(\ZipArchive $archive, $minCompressionRatioToBeBomb = 200)
    {
        if (!$archive->filename) {
            throw new common_Exception('ZIP archive should be opened before checking for a ZIP bomb');
        }

        $contentSize = 0;
        for ($fileIndex = 0; $fileIndex < $archive->numFiles; $fileIndex++) {
            $stats = $archive->statIndex($fileIndex);
            $contentSize += $stats['size'];
        }

        $archiveFileSize = filesize($archive->filename);

        return $archiveFileSize * $minCompressionRatioToBeBomb < $contentSize;
    }
public static function checkWhetherArchiveIsBomb(\ZipArchive $archive, $minCompressionRatioToBeBomb = 200)
    {
        if (!$archive->filename) {
            throw new common_Exception('ZIP archive should be opened before checking for a ZIP bomb');
        }

        $contentSize = 0;
        for ($fileIndex = 0; $fileIndex < $archive->numFiles; $fileIndex++) {
            $stats = $archive->statIndex($fileIndex);
            $contentSize += $stats['size'];
        }

        $archiveFileSize = filesize($archive->filename);

        return $archiveFileSize * $minCompressionRatioToBeBomb < $contentSize;
    }
public static function checkWhetherArchiveIsBomb ( \ ZipArchive $ archive , $ minCompressionRatioToBeBomb = 200 ) { if ( ! $ archive -> filename ) { throw new common_Exception ( 'ZIP archive should be opened before checking for a ZIP bomb' ) ; } $ contentSize = 0 ; for ( $ fileIndex = 0 ; $ fileIndex < $ archive -> numFiles ; $ fileIndex ++ ) { $ stats = $ archive -> statIndex ( $ fileIndex ) ; $ contentSize += $ stats [ 'size' ] ; } $ archiveFileSize = filesize ( $ archive -> filename ) ; return $ archiveFileSize * $ minCompressionRatioToBeBomb < $ contentSize ; }
Helps prevent decompression attacks.
Since this method checks archive file size, it needs filename property to be set,
so ZipArchive object should be already opened.

@param \ZipArchive $archive
@param int $minCompressionRatioToBeBomb archive content size / archive size
@return bool
@throws common_Exception

@link https://en.wikipedia.org/wiki/Zip_bomb
Helps prevent decompression attacks . Since this method checks archive file size it needs filename property to be set so ZipArchive object should be already opened .