Skip to content

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

Conversation

mmezhensky
Copy link

Description (*)

This PR adjusted validation for images files in ICO format.

Fixed Issues (if relevant)

  1. Fixes Favicon Icon upload form in Magento does not actually support .ico file types #34858

Manual testing scenarios (*)

  1. Login to Magento admin
  2. Navigate to Content -> Design -> Configuration
  3. Click 'Edit' on any of the records shown in the grid
  4. Scroll to 'Other Settings'
  5. Expand 'HTML Head'
  6. Under the 'Favicon Icon' section, click 'Upload'
  7. Select a valid .ico file, click 'Open'

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Dec 24, 2021

Hi @mmezhensky. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

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.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 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

@mmezhensky
Copy link
Author

@magento run all tests

@magento-automated-testing
Copy link

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.

Comment on lines 67 to 69
$imagick = new \Imagick();
$imagick->setFormat('ICO');
$image = $imagick->readImageBlob($this->file->fileGetContents($filePath));
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Author

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.

СС @ihor-sviziev

Copy link
Contributor

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.

Copy link
Author

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).

Copy link
Contributor

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?

Copy link
Author

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!

Comment on lines 67 to 69
$imagick = new \Imagick();
$imagick->setFormat('ICO');
$image = $imagick->readImageBlob($this->file->fileGetContents($filePath));
Copy link
Contributor

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.

@m2-community-project m2-community-project bot added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jan 13, 2022
@magento-engcom-team
Copy link
Contributor

Hi @Den4ik, thank you for the review.
ENGCOM-9397 has been created to process this Pull Request
✳️ @Den4ik, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@Den4ik Den4ik added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Feb 3, 2022
@Den4ik
Copy link
Contributor

Den4ik commented Feb 3, 2022

@mmezhensky Could you add unit tests for implemented changes?

@engcom-Delta
Copy link
Contributor

❌ QA not Passed

Favicon Icon upload form does not support .ico file types in Magento 2.4 Develop.

Preconditions:

  1. We should have fresh installation of Magento 2.4 Develop.
  2. We should have .Ico files ready for uploading

Manual Scenario Steps

  1. Log in to Magento admin
  2. Navigate to Content -> Design -> Configuration
  3. Click 'Edit' on any of the records shown in the grid
  4. Scroll to 'Other Settings'
  5. Expand 'HTML Head'
  6. Under the 'Favicon Icon' section, click 'Upload'
  7. Select a valid “.ico” extension file, click 'Open'
  8. Validate the file upload results

✔️ Expected result After Fix

  • .Ico files should be uploaded successfully.

❌ Actual result After Fix

  • .Ico files are not getting uploaded, throwing the ''File validation Failed " popup

FYI- downloaded the ico files from link

Copy link
Contributor

@engcom-Delta engcom-Delta left a 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

@engcom-Lima
Copy link
Contributor

Hi @engcom-Delta,
Magento by default uses GD Library which does not support ico extension.
In order to verify the issue, the ImageMagick extension needs to be set in Stores->Configuration->Advanced->Developer->Image Processing Settings

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!

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

Preconditions:

  1. Have ImageMagic installed in your system and extension enabled under server php.ini; REFER HERE
  2. Have Magento latest installed.
  3. Have some .ico files in the system to upload; here is - ico files downloadable link

Manual testing scenario:

  1. Log in to Magento admin; Navigate to Content -> Design -> Configuration

  2. Click 'Edit' on any of the records shown in the grid > Scroll to 'Other Settings' > Expand 'HTML Head'

  3. Under the 'Favicon Icon' section, click 'Upload'; Select a valid “.ico” extension file, click 'Open'

  4. Validate the file upload results

Before: ✖️ We were getting an error message "File Validation Failed".

image

After: ✔️ File is getting uploaded successfully.

image

Tried to save the uploaded ico file and getting it saved successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests Component: Image Component: MediaStorage Partner: Atwix Pull Request is created by partner Atwix partners-contribution Pull Request is created by Magento Partner Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Favicon Icon upload form in Magento does not actually support .ico file types
9 participants