Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/ClamAV/ClamAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,35 @@ public function fileScanInStream(string $file): bool
*/
public function fileScan(string $file): bool
{
$out = $this->sendCommand('SCAN ' . $file);
$response = $this->sendCommand('SCAN ' . $file);

$out = \explode(':', $out);
$stats = \end($out);
if (!is_string($response) || trim($response) === '') {
throw new \RuntimeException('Empty or invalid response from ClamAV daemon.');
}

return \trim($stats) === 'OK';
// Expected format: "/path/to/file: STATUS"
$parts = explode(':', $response);

if (count($parts) < 2) {
throw new \RuntimeException(
'Unexpected ClamAV response format: ' . $response
);
}

$status = trim(end($parts));

if ($status === 'OK') {
return true; // Clean
}

if (str_ends_with($status, 'FOUND')) {
return false; // Infected
}

// Any other output (e.g. "ERROR", "UNKNOWN", empty, etc.) → exception
throw new \RuntimeException(
'Unexpected ClamAV status: ' . $status . ' | Full response: ' . $response
);
}

/**
Expand Down