Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaHelper: proper check if file is an image (#42105) #43345

Open
wants to merge 1 commit into
base: 4.4-dev
Choose a base branch
from

Conversation

coderiekelt
Copy link

Pull Request for Issue #42105.

Summary of Changes

  • Changed MediaHelper.php to properly check if the uploaded file is actually an image, instead of assuming true.

Testing Instructions

Upload a PDF file to the media library, this should work properly. Uploading images will also still work fine in accordance with previous behavior.

Actual result BEFORE applying this Pull Request

Uploading a PDF fails, providing an unhelpful error to the user. When checking the request in within the browser the message is along the lines of "This is not a valid image".

Expected result AFTER applying this Pull Request

Uploading a PDF works fine, uploading images still follows the previous behavior.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

@brianteeman
Copy link
Contributor

unable to test as I cannot replicate the reported error

@coderiekelt
Copy link
Author

coderiekelt commented Apr 24, 2024

After some digging it appears that this error occurs if the exif extension is not loaded.

A simple test script to get the MIME type from a blank PDF file yielded this result:

getimagesize: unknown (false)
exif_imagetype: application/octet-stream

Meaning this problem will not occur if the exif extension is loaded, since it will return application/octet-stream. (Which is properly detected further down in the function.)

If exif is not loaded it will fail, since the MediaHelper will assume that the file is always an image and just gives up after trying getimagesize() due to the way the way the if statement within this function is structured.

@brianteeman
Copy link
Contributor

i can confirm that this issue occurs when exif is not available.

@brianteeman
Copy link
Contributor

Some history #16086

Which should have been fixed with #16091

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants