Skip to content

Commit

Permalink
Fixed bug on users not able to modify image quality in backend if dep…
Browse files Browse the repository at this point in the history
…recated config exists.
  • Loading branch information
kiatng committed Oct 1, 2022
1 parent 2df1069 commit 12071f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
13 changes: 9 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 @@ -75,6 +75,7 @@ public function setAllowedImageTypes(array $imageFileExtensions = [])

/**
* 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,11 +86,15 @@ public function validate($filePath)
list($imageWidth, $imageHeight, $fileType) = getimagesize($filePath);
if ($fileType) {
if ($this->isImageType($fileType)) {
/** Check deprecated 'general/reprocess_images/active' for BC. If false then skip image reprocessing. */
if (Mage::getStoreConfig('general/reprocess_images/active') !== null) {
$imageQuality = Mage::getStoreConfigFlag('general/reprocess_images/active') ? 100 : 0;
// Config 'general/reprocess_images/active' is deprecated, replacement is the following:
$imageQuality = Mage::getStoreConfig('admin/security/reprocess_image_quality');
if ($imageQuality !== null) {
$imageQuality = (int) $imageQuality;
} else {
$imageQuality = (int) Mage::getStoreConfig('admin/security/reprocess_image_quality');
// 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;
Expand Down
1 change: 0 additions & 1 deletion app/code/core/Mage/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@
<extensions_compatibility_mode>1</extensions_compatibility_mode>
<session_cookie_lifetime>10800</session_cookie_lifetime>
<secure_system_configuration_save_disabled>0</secure_system_configuration_save_disabled>
<reprocess_image_quality>85</reprocess_image_quality>
</security>
</admin>
<general>
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1282,8 +1282,8 @@
</crate_admin_user_notification>
<reprocess_image_quality translate="label comment">
<label>Image Reprocess Quality</label>
<comment>Optimum value is 85, higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks.</comment>
<validate>required-entry validate-digits validate-digits-range digits-range-0-100</validate>
<comment>Optimum value is 85 (default), higher value will increase file size. Set to 0 to turn off images reprocessing, which 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>
Expand Down
2 changes: 1 addition & 1 deletion app/locale/en_US/Mage_Core.csv
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"New Website","New Website"
"No","No"
"Offloader header","Offloader header"
"Optimum value is 85, higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks.","Optimum value is 85, higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks."
"Optimum value is 85 (default), higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks.","Optimum value is 85 (default), higher value will increase file size. Set to 0 to turn off images reprocessing, which may cause security risks."
"PHP SOAP extension is required.","PHP SOAP extension is required."
"Package","Package"
"Pagination","Pagination"
Expand Down

0 comments on commit 12071f7

Please sign in to comment.