fix(previews): Stop returning true when getimagesize()
fails
#46342
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Our
checkImageSize()
&checkImageDataSize()
methods always returntrue
if an image is corrupt/invalid1 (or unreadable). However, whengetimagesize()
returnsfalse
so shouldcheckImage*()
IMO.This current behavior causes already detected invalid images to not only bypass the
checkImageMemory()
check (as intended), but to continue to be processed in other ways even though they'll fail.This impacts all formats, not just jpeg (though most are covered by suppressors at this point).
One could argue the current situation is valid behavior since the intention of the
checkImage*
methods isn't to detect other types of image problems, so it's a bit of an overloaded use. But in all cases I can conceive of, other image manipulations are going to fail anyhow ifgetimagesize()
does. And we're immediately callinggetimagesize()
once again in many cases.P.S. With the fix to
checkImageSize()
, the line with the suppressor shouldn't even be executed any longer. The suppressor added here is just for good measure and to be consistent with the other image formats. If the behavior of thecheckImage*()
methods is desired to be retained as-is, I can eliminate those changes and keep only the suppressor.TODO
Checklist
Footnotes
(or at least corrupt enough their image data can't be retrieved by gd) ↩