file_validate_image_resolution doesn't not update file size after resizing

Created on 23 June 2022, over 2 years ago
Updated 14 February 2023, almost 2 years ago

Problem/Motivation

When an image operation occurs at file_validate_image_resolution, the file object's filesize is not update until the presave of the file.
All operations between these two steps will get the original file size which could lead to errors.
For example the ClamAV module needs it in its hook_file_validate (see issue https://www.drupal.org/project/clamav/issues/3058018 🐛 Use of Max Resolution on Image Field causes ClamAV Timeout in Deamon mode Needs review )

Steps to reproduce

  1. Set an image field with max_resolution settings.
  2. Add a xdebug break point at the end of file_validate_image_resolution
  3. Add a xdebug break point in a hook_file_validate()
  4. Upload a file bigger than the max resolution
  5. When the first break point is triggered, compare the values of $file->getSize() (original size) and $image->getFileSize() (resized size)
  6. On the second breakpoint $file->getSize() still display the original size
  7. After image is saved, check that the size is correct in the file_managed table

Proposed resolution

Update the $file->setSize() (or any other metadata) after any file manipulations in file_validate_image_resolution() function.

Remaining tasks

  1. Add a new test ?

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Needs work

Version

10.1

Component
Image system 

Last updated 1 day ago

Created by

🇫🇷France O'Briat Nantes

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024