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

Fixes issue #475, reduce reprocessed jpeg image file size by defaulting image quality to 85% #2629

Merged
merged 5 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions app/code/core/Mage/Core/Model/File/Validator/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function setAllowedImageTypes(array $imageFileExtensions = [])
}

/**
* Validation callback for checking is file is image
* Validation callback for checking if file is image
* Destroy malicious code in image by reprocessing
*
* @param string $filePath Path to temporary uploaded file
* @return null
Expand All @@ -85,8 +86,17 @@ public function validate($filePath)
list($imageWidth, $imageHeight, $fileType) = getimagesize($filePath);
if ($fileType) {
if ($this->isImageType($fileType)) {
/** if 'general/reprocess_images/active' false then skip image reprocessing. */
if (!Mage::getStoreConfigFlag('general/reprocess_images/active')) {
// Config 'general/reprocess_images/active' is deprecated, replacement is the following:
$imageQuality = Mage::getStoreConfig('admin/security/reprocess_image_quality');
if ($imageQuality != '') {
$imageQuality = (int) $imageQuality;
} else {
// Value not set in backend. For BC, if depcrecated config does not exist, default to 85.
$imageQuality = Mage::getStoreConfig('general/reprocess_images/active') === null
? 85
: (Mage::getStoreConfigFlag('general/reprocess_images/active') ? 85 : 0);
}
if ($imageQuality === 0) {
return null;
}
//replace tmp image with re-sampled copy to exclude images with malicious data
Expand Down Expand Up @@ -116,7 +126,7 @@ public function validate($filePath)
imagegif($img, $filePath);
break;
case IMAGETYPE_JPEG:
imagejpeg($img, $filePath, 100);
imagejpeg($img, $filePath, $imageQuality);
break;
case IMAGETYPE_PNG:
imagepng($img, $filePath);
Expand Down
4 changes: 0 additions & 4 deletions app/code/core/Mage/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,6 @@
</protected>
</public_files_valid_paths>
</file>
<!-- NOTE: If you turn off images reprocessing, then your upload images process may cause security risks. -->
<reprocess_images>
<active>1</active>
</reprocess_images>
<!-- Additional email for notifications -->
<additional_notification_emails>
<!-- On creating a new admin user. You can specify several emails separated by commas. -->
Expand Down
9 changes: 9 additions & 0 deletions app/code/core/Mage/Core/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,15 @@
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</crate_admin_user_notification>
<reprocess_image_quality translate="label comment">
<label>Image Reprocess Quality</label>
<comment>The recommended value is 85, a higher value will increase the file size. You can set the value to 0 to disable image processing, but it may cause security risks.</comment>
<validate>validate-digits validate-digits-range digits-range-0-100</validate>
<sort_order>180</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</reprocess_image_quality>
</fields>
</security>
<dashboard translate="label">
Expand Down
2 changes: 2 additions & 0 deletions app/locale/en_US/Mage_Core.csv
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"How many links to display at once.","How many links to display at once."
"ID Path for Specified Store","ID Path for Specified Store"
"If the current frame position does not cover utmost pages, will render link to current position plus/minus this value.","If the current frame position does not cover utmost pages, will render link to current position plus/minus this value."
"Image Reprocess Quality","Image Reprocess Quality"
"Incorrect credit card expiration date.","Incorrect credit card expiration date."
"Input type ""%value%"" not found in the input types list.","Input type ""%value%"" not found in the input types list."
"Invalid MIME type.","Invalid MIME type."
Expand Down Expand Up @@ -226,6 +227,7 @@
"New Website","New Website"
"No","No"
"Offloader header","Offloader header"
"The recommended value is 85, a higher value will increase the file size. You can set the value to 0 to disable image processing, but it may cause security risks.","The recommended value is 85, a higher value will increase the file size. You can set the value to 0 to disable image processing, but it may cause security risks."
"PHP SOAP extension is required.","PHP SOAP extension is required."
"Package","Package"
"Pagination","Pagination"
Expand Down