-
Notifications
You must be signed in to change notification settings - Fork 9.4k
34858: Adjust validation for upload ICO files #34883
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
34858: Adjust validation for upload ICO files #34883
Conversation
Hi @mmezhensky. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review. For more details, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run all tests |
The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time. |
$imagick = new \Imagick(); | ||
$imagick->setFormat('ICO'); | ||
$image = $imagick->readImageBlob($this->file->fileGetContents($filePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's a good option because the Imagick extension is currently optional, and by default, Magento uses lib gd.
Can it handle this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ihor-sviziev
Lib GD does not support the ICO
format and error returns.
After a long search for a solution, I think Imagick is the most suitable option, or we will have to install a third-party extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmezhensky I'm OK with using imagick when it's available. But when it's not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ihor-sviziev Imagick
is already used in Magento.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but only as optional dependence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Den4ik
Thanks for your information, but I tried to do it, and I always get an error for ICO
files because GD2
does not support this format, and Magento\Framework\Image\Adapter\ImageMagick
has no function for setting ICO
format.
To use Magento\Framework\Image\Factory
, we always need to pass $adapterName = "IMAGEMAGICK"
and extend Magento\Framework\Image\Adapter\ImageMagick
class to add the ability to install the form.
But I think it will be a significant change in the Magento Framework that may cause problems in the future, so I suggest using the fix option I suggested earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mmezhensky. Thanks for your work.
we always need to pass $adapterName = "IMAGEMAGICK"
It's not quite true. AdapterFactory retrieve current selected adapter from stores configuration. And my mind is that we receive exception if imagick is not selected as adapter at Stores config. It's guarant that user/administrator that select imagick as adapter will be sure that it's installed for php.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Den4ik
Yes, but even if imagick is installed in the configuration and it is installed on the server, we will still get an exception because we need to set ICO format for the imagick object (but we can't do it without changes in Magento\Framework\Image\Adapter\ImageMagick
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmezhensky I agree that it require some changes for ImageMagick
class, but I don't see any problems use something like that in open
method
if (is_callable('exif_imagetype')) {
$fileType = exif_imagetype($this->_fileName);
if ($fileType === IMAGETYPE_ICO) {
$filename = 'ico:' . $filename;
}
}
$this->_imageHandler = new \Imagick($filename);
It provide total support of ico files for image magick adapter
@ihor-sviziev @sidolov What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prepared these changes.
Thx!
$imagick = new \Imagick(); | ||
$imagick->setFormat('ICO'); | ||
$image = $imagick->readImageBlob($this->file->fileGetContents($filePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmezhensky I'm agree with @ihor-sviziev and believe that we could use Magento\Framework\Image\Factory
here because it will use default adapter selected in configs.
If call of open
throw exception than image is not valid.
Hi @Den4ik, thank you for the review.
|
@mmezhensky Could you add unit tests for implemented changes? |
❌ QA not Passed Favicon Icon upload form does not support .ico file types in Magento 2.4 Develop. Preconditions:
Manual Scenario Steps
✔️ Expected result After Fix
❌ Actual result After Fix
FYI- downloaded the ico files from link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution and collaboration @mmezhensky , @ihor-sviziev and @Den4ik
Based on the above comments moving to 'Request Changes' status
Hi @engcom-Delta, Note: ImageMagic needs to be installed on server in order to set the ImagMagic option in magento. Request you to kindly verify the issue after installing ImageMagic on server and setting it as the default adapter Thanks! |
✔️ QA Passed Preconditions:
Manual testing scenario:
Before: ✖️ We were getting an error message "File Validation Failed". After: ✔️ File is getting uploaded successfully. Tried to save the uploaded ico file and getting it saved successfully. |
Description (*)
This PR adjusted validation for images files in ICO format.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)