FileValidationEvent is not drop-in replacement for hook_file_validate

Created on 12 February 2025, 3 months ago

Problem/Motivation

https://www.drupal.org/node/3363700 โ†’ advises modules to move from hook_file_validate to use FileValidationEvent instead.

It appears that in some cases, this is not a suitable replacement.

Steps to reproduce

ClamAV contrib module switched from hook_file_validate to FileValidationEvent and it appears that in some cases, the file scanning logic now breaks.

If we log file size (uploading test PNG file on one of the content types - image field, but same problem with other file upload fields) as reported by the FileInterface in both FileValidationEvent and hook_file_validate, it seems they return different data.

$file_size = filesize($file->getFileUri());
\Drupal::logger('File validate')->error('Size of file is: ' . $file->getSize() . ', URI is: ' . $file->getFileUri() . ' file size is: ' . $file_size);

Using hook_file_validate, this logs

Size of file is: 387365, URI is: /tmp/phpzipzoE file size is: 387365

but using FileValidationEvent logs

Size of file is: 387365, URI is: /tmp/phpuX8xcs file size is: 506707

Should modules such as ClamAV use some other event than FileValidationEvent to make sure the physical file is the correct one and fully processed before doing custom validations?

๐Ÿ› Bug report
Status

Active

Version

10.5 โœจ

Component

file system

Created by

๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024