@@ -36,7 +36,7 @@ final class ArchiveLimitInspector
|
||||
$expandedBytes = 0;
|
||||
for ($index = 0; $index < $archive->numFiles; $index++) {
|
||||
$entry = $archive->statIndex($index);
|
||||
if (! is_array($entry) || ! isset($entry['size']) || ! is_int($entry['size']) || $entry['size'] < 0) {
|
||||
if (! is_array($entry) || $entry['size'] < 0) {
|
||||
return 'archive_inspection_failed';
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ final class ClamDScanner implements MalwareScanner
|
||||
}
|
||||
$offset += $written;
|
||||
$meta = stream_get_meta_data($socket);
|
||||
if ($meta['timed_out'] ?? false) {
|
||||
if ($meta['timed_out']) {
|
||||
throw new RuntimeException('ClamD scan timed out while sending data.');
|
||||
}
|
||||
}
|
||||
@@ -208,19 +208,21 @@ final class ClamDScanner implements MalwareScanner
|
||||
{
|
||||
$reply = stream_get_line($socket, 65536, "\0");
|
||||
$meta = stream_get_meta_data($socket);
|
||||
if ($reply === false || ($meta['timed_out'] ?? false)) {
|
||||
throw new RuntimeException(($meta['timed_out'] ?? false) ? 'ClamD scan timed out.' : 'ClamD returned no scan result.');
|
||||
if ($reply === false || $meta['timed_out']) {
|
||||
throw new RuntimeException($meta['timed_out'] ? 'ClamD scan timed out.' : 'ClamD returned no scan result.');
|
||||
}
|
||||
|
||||
return trim($reply);
|
||||
}
|
||||
|
||||
/** @return array{available:bool,engine:string,engine_version:?string,signatures_at:?DateTimeImmutable,signature_age_hours:?float,reason_code:?string} */
|
||||
private function unavailable(string $reason): array
|
||||
{
|
||||
return ['available' => false, 'engine' => 'ClamAV', 'engine_version' => null, 'signatures_at' => null,
|
||||
'signature_age_hours' => null, 'reason_code' => $reason];
|
||||
}
|
||||
|
||||
/** @return array{result:string,reason_code:?string,engine:string,engine_version:string,signatures_at:?DateTimeImmutable,duration_ms:int,detail:?string} */
|
||||
private function result(string $result, ?string $reason, int $startedAt, ?string $detail): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Services\Malware;
|
||||
|
||||
interface MalwareScanner
|
||||
{
|
||||
/** @return array{result:string,reason_code:?string,engine:string,engine_version:string,signatures_at:\DateTimeImmutable,duration_ms:int,detail:?string} */
|
||||
/** @return array{result:string,reason_code:?string,engine:string,engine_version:string,signatures_at:?\DateTimeImmutable,duration_ms:int,detail:?string} */
|
||||
public function scan(string $path, int $fileSizeBytes, string $storageRoot): array;
|
||||
|
||||
/** @return array{available:bool,engine:string,engine_version:?string,signatures_at:?\DateTimeImmutable,signature_age_hours:?float,reason_code:?string} */
|
||||
|
||||
Reference in New Issue
Block a user