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 misuse of information returned by getimagesize #11809

Merged
merged 2 commits into from Dec 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions classes/ImageManager.php
Expand Up @@ -123,13 +123,15 @@ public static function checkImageMemoryLimit($image)

$memoryLimit = Tools::getMemoryLimit();
// memory_limit == -1 => unlimited memory
if (function_exists('memory_get_usage') && (int) $memoryLimit != -1) {
if (isset($infos['bits']) && function_exists('memory_get_usage') && (int) $memoryLimit != -1) {
$currentMemory = memory_get_usage();
$channel = isset($infos['channels']) ? ($infos['channels'] / 8) : 1;

$bits = $infos['bits'] / 8;
$channel = isset($infos['channels']) ? $infos['channels'] : 1;

// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
// For perfs, avoid computing static maths formulas in the code. pow(2, 16) = 65536 ; 1024 * 1024 = 1048576
if (($infos[0] * $infos[1] * $infos['bits'] * $channel + 65536) * 1.8 + $currentMemory > $memoryLimit - 1048576) {
if (($infos[0] * $infos[1] * $bits * $channel + 65536) * 1.8 + $currentMemory > $memoryLimit - 1048576) {
return false;
}
}
Expand Down