- ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
kim.pepper โ made their first commit to this issueโs fork.
- Status changed to Needs review
10 months ago 10:26pm 27 March 2024 - ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
We should suppress the warning, and check if
@filesize()
returnsFALSE
. Also\Drupal\Core\Image\ImageInterface::getFileSize()
expects this to beNULL
notFALSE
if the file is invalid, so we should handle that too. - ๐ฆ๐บAustralia pameeela
Issue summary updated. I can't really provide steps to reproduce as it requires a custom architecture to host files on s3.
- Status changed to Needs work
10 months ago 1:34pm 28 March 2024 - ๐บ๐ธUnited States smustgrave
Possible to add test coverage for when it is NULL?
- First commit to issue fork.
- ๐ช๐ธSpain vidorado Pamplona (Navarra)
I've added a couple of tests and attempted to simulate an S3 filesystem where
filesize()
returnsFALSE
, even though the toolkit returnsTRUE
inparseFile()
- ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
Good test coverage. I ran the test-only pipeline and it fails as expected. The current docblock already says it should return
int|null
so there is no API breaks afaik, and we don't need a change record for a bug fix. I think we are safe to RTBC. - ๐ช๐ธSpain vidorado Pamplona (Navarra)
Thanks for the review @kim.pepper!
Mind the "null" in the @return of the docblock was added in this issue, it wasnยดt already there: https://git.drupalcode.org/project/drupal/-/merge_requests/7217/diffs?co...
I believe that in the cases where a false was taken into account, it would have been with a simple truthy evaluation if($value). I think it's rare that anyone could have used if(FALSE === $value), so the NULL is probably not harming.
- ๐ฌ๐งUnited Kingdom alexpott ๐ช๐บ๐
We need to add a comment about why we're suppressing errors here.
- ๐ฆ๐บAustralia kim.pepper ๐โโ๏ธ๐ฆ๐บSydney, Australia
Feedback resolved. Back to RTBC
- ๐ฎ๐นItaly mondrake ๐ฎ๐น
Looking at the motivation, I am not sure about this. The file must have a size, but we cannot get it so we hide the problem. BTW possibly the image cannot be loaded by GD either. IMHO the right solution here would be to download the file from S3 to local storage, get its stats and use it for manipulation. IIRC the ImageMagick toolkit does something similar since it does not support stream wrappers.
- ๐บ๐ธUnited States mfb San Francisco
filesize() can return zero for empty files; in this case, zero should be returned, not NULL
- ๐ช๐ธSpain vidorado Pamplona (Navarra)
I agree with you @mfb, and I took that into account, but it's an imposible case, as the toolkit will never validate an image as valid if the file is zero size.
- ๐ช๐ธSpain vidorado Pamplona (Navarra)
Sorry, I didn't see @mondrake's comment. I agree that returning NULL is hiding the problem in the case of a VALID image. However, I stand by saying that zero should never be returned by
getFileSize()
, since its docblock states this:/** * Returns the size of the image file. * * @return int|null * The size of the file in bytes, or NULL if the image is invalid. */ public function getFileSize();
A zero size image would never be valid, so a NULL must be returned. But in case of a valid image that we can't retrieve easily with
filesize()
... returning NULL is wrong, that seems clear.I will take a look at the ImageMagick toolkit to get ideas about how to download and parse the file from S3.
Thanks all for the fedback! :)
- ๐บ๐ธUnited States mfb San Francisco
Ok, sounds reasonable to not worry about the zero size case then (would only happen in edge cases like buggy toolkit, file getting truncated by another process etc.)
- ๐ช๐ธSpain vidorado Pamplona (Navarra)
I've installed an AWS S3 mock with Localstack and amazon-ec2-metadata-mock.
Then, I've been able to check that
filesize()
works well with as3://
stream.Perhaps this is not longer an issue? I don't have a real S3 bucket, maybe someone could do a real test.
- ๐บ๐ธUnited States smustgrave
Believe feedback has been addressed for this one.