Skip to content

Add lenient mode to ICO decoder#3001

Open
mpospelova wants to merge 1 commit into
image-rs:mainfrom
mpospelova:ico-lenient-mode
Open

Add lenient mode to ICO decoder#3001
mpospelova wants to merge 1 commit into
image-rs:mainfrom
mpospelova:ico-lenient-mode

Conversation

@mpospelova
Copy link
Copy Markdown
Contributor

Add lenient mode to ICO decoder

Ignore dimension mismatch in lenient mode and decode the image using the embedded image's dimensions

@RunDevelopment
Copy link
Copy Markdown
Member

I also tested your example file in a few programs, and the results are interesting:

  1. Windows Explorer decodes it as a 2x2 image and correctly decodes color (I tested this by modifying the colors of the BMP).
  2. Gimp decodes it as a 3x3 image. The 2x2 BMP is placed at the top left corner and everything else is transparent.
  3. Chrome decodes it as a 3x3 image, but all colors are white even when I hex-edit the BMP to have different colors.
  4. Firefox refuses to open it.

When I hex-edit the ICO file to report a size of 1x2 (while the BMP stays 2x2), results are similar. The only difference is that Gimp decodes it as full transparent.

Since Windows is the authority when it comes to ICO files, I think your behavior is correct. Windows seems to ignore the size reported by ICO files and use the underlying size directly.

So I am generally on board with this change.

However, I think we need to change the implementation a little.

  1. Only the BMP path is truly lenient. The PNG path sets a dimension limit on the decoder, so that needs to be changed to behave the same as BMP. I think a hard-coded max size of 256x256 should be fine.
  2. I think we should still reject images with a dimension >256. It's just very unexpected for ICO files to be larger than that.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants