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

Fix : check if is_file in getMimeType #590

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

Conversation

julienmiclo
Copy link

Hello,
on my localhost i have some warning when filename are check with getMimeType function.

I added an if condition around 4 Try with mime type.

Copy link
Contributor

@matks matks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello in order to understand why you added these options, we would need to understand what situation you were in 😉

}
if (!$mimeType) {
$mimeType = trim(exec('file -bi ' . escapeshellarg($filename)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waaaaah 🤯 I did not know this code performed an exec... it's a bit frightening 😅 for security issues

@julienmiclo
Copy link
Author

Hello,
i uploaded some SVG file from figma.
I place the module in displayFooterBefore and when i go on my frontpage, i have this error :

Warning: finfo_file(/Users/julienmiclo/WebServer/repositories/shop/modules/blockreassurance/views/img/img_perso/icon-fast-delivery.svg): Failed to open stream: No such file or directory in /Users/julienmiclo/WebServer/repositories/iello-shop/modules/blockreassurance/classes/ReassuranceActivity.php on line 187

Warning: mime_content_type(/Users/julienmiclo/WebServer/repositories/shop/modules/blockreassurance/views/img/img_perso/icon-fast-delivery.svg): Failed to open stream: No such file or directory in /Users/julienmiclo/WebServer/repositories/shop/modules/blockreassurance/classes/ReassuranceActivity.php on line 192

but all my files is in the right folder. If you check if is a file before get mime type, it's avoid the warning.
regards

@matks
Copy link
Contributor

matks commented Sep 25, 2023

Thanks @julienmiclo so if I understand

  1. Install blockreassurance v5.1.2 on prestashop 8.1.1
  2. Hook module to displayFooterBefore
  3. From BO blockreassurance configuration page, upload custom SVG files to be used in blocks
  4. Go on homepage, see error

@matthieu-rolland matthieu-rolland added this to the 5.1.5 milestone Nov 8, 2023
@leemyongpakvn
Copy link
Contributor

leemyongpakvn commented Nov 11, 2023

According to AdminBlockListingController.php#L178-L201, we can use ImageManager::validateUpload ImageManager::getMimeType instead of ReassuranceActivity::getMimeType since PS 1.7.7.0, so we can solve above issues by bumping min compat. to PS 1.7.7 and replacing getMimeType by validateUpload completely in Release 6.0.0 .;)

@leemyongpakvn leemyongpakvn modified the milestones: 5.1.5, 6.0.0 Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

4 participants