ZIP and PNG bomb scanner for PHP.
- Detection of ZIP archive bombs
- Detection of RAR archive bombs
- Detection of PNG bombs
- No dependencies
- Very fast
- PHP 8.1+
composer require selective/archive-bomb-scanner
use Selective\ArchiveBomb\Scanner\BombScanner;
use Selective\ArchiveBomb\Engine\ZipBombEngine;
use SplFileObject;
$file = new SplFileObject('42.zip');
$scanner = new BombScanner();
$scanner->addEngine(new ZipBombEngine());
$scannerResult = $scanner->scanFile($file);
if ($scannerResult->isBomb()) {
echo 'Archive bomb detected!';
} else {
echo 'File is clean';
}
use Selective\ArchiveBomb\BombScanner;
use Selective\ArchiveBomb\Engine\ZipBombEngine;
use SplTempFileObject;
$file = new SplTempFileObject();
$file->fwrite('my file content');
$scanner = new BombScanner();
$scanner->addEngine(new ZipBombEngine());
$isBomb = $detector->scanFile($file)->isBomb(); // true or false
use Selective\ArchiveBomb\Scanner\BombScanner;
use Selective\ArchiveBomb\Engine\RarBombEngine;
use SplFileObject;
$file = new SplFileObject('10GB.rar');
$scanner = new BombScanner();
$scanner->addEngine(new RarBombEngine());
$scannerResult = $scanner->scanFile($file);
if ($scannerResult->isBomb()) {
echo 'Archive bomb detected!';
} else {
echo 'File is clean';
}
use Selective\ArchiveBomb\Scanner\BombScanner;
use Selective\ArchiveBomb\Engine\PngBombEngine;
use SplFileObject;
$file = new SplFileObject('example.png');
$scanner = new BombScanner();
$scanner->addEngine(new PngBombEngine());
$scannerResult = $scanner->scanFile($file);
if ($scannerResult->isBomb()) {
echo 'PNG bomb detected!';
} else {
echo 'File is clean';
}
MIT