Skip to content

Commit

Permalink
allow passing stream directly to scanner (#68)
Browse files Browse the repository at this point in the history
* allow passing stream directly to scanner

* moved resource check out of getFilename method to validateFileWithClamAv

* removed double spaces
  • Loading branch information
bnoordsij committed Mar 18, 2024
1 parent 0db1864 commit 2696ff5
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/ClamavValidator/ClamavValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(
*/
public function validateClamav(string $attribute, $value, array $parameters): bool
{
if (filter_var(Config::get('clamav.skip_validation'), FILTER_VALIDATE_BOOLEAN)) {
if (filter_var(Config::get('clamav.skip_validation'), FILTER_VALIDATE_BOOLEAN)) {
return true;
}

Expand All @@ -71,15 +71,20 @@ public function validateClamav(string $attribute, $value, array $parameters): bo
*/
protected function validateFileWithClamAv($value): bool
{
$file = $this->getFilePath($value);
if (! is_readable($file)) {
throw ClamavValidatorException::forNonReadableFile($file);
if (is_resource($value)) {
$file = $value;
} else {
$file = $this->getFilePath($value);
if (! is_readable($file)) {
throw ClamavValidatorException::forNonReadableFile($file);
}
}

try {
$socket = $this->getClamavSocket();
$socket = $this->getClamavSocket();
$scanner = $this->createQuahogScannerClient($socket);
$result = $scanner->scanResourceStream(fopen($file, 'rb'));
$stream = is_resource($file) ? $file : fopen($file, 'rb');
$result = $scanner->scanResourceStream($stream);
} catch (Exception $exception) {
if (Config::get('clamav.client_exceptions')) {
throw ClamavValidatorException::forClientException($exception);
Expand Down

0 comments on commit 2696ff5

Please sign in to comment.