Skip to content

Fix : check if is_file in getMimeType#590

Open
julienmiclo wants to merge 1 commit into
PrestaShop:devfrom
julienmiclo:dev-1
Open

Fix : check if is_file in getMimeType#590
julienmiclo wants to merge 1 commit into
PrestaShop:devfrom
julienmiclo:dev-1

Conversation

@julienmiclo

Copy link
Copy Markdown

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.

@matks matks left a comment

Copy link
Copy Markdown
Contributor

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 😉

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

Copy link
Copy Markdown
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
Copy Markdown
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

matks commented Sep 25, 2023

Copy link
Copy Markdown
Contributor

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

leemyongpakvn commented Nov 11, 2023

Copy link
Copy Markdown
Contributor

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