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

.ico coder needs magic number detection (coders/icon.c) #4230

Closed
gurgeous opened this issue Sep 15, 2021 · 3 comments
Closed

.ico coder needs magic number detection (coders/icon.c) #4230

gurgeous opened this issue Sep 15, 2021 · 3 comments

Comments

@gurgeous
Copy link

Is your feature request related to a problem? Please describe.

The ICO coder lacks magic number detection. You can see this behavior on the command line. These two files are identical:

$ identify favicon.bogus favicon.ico
favicon.ico[0] ICO 48x48 48x48+0+0 8-bit sRGB 0.000u 0:00.001
identify: no decode delegate for this image format `BOGUS' @ error/constitute.c/ReadImage/575.

The real problem is when favicons are loaded from the network using the various API bindings. For example, with the go bindings you have to save the .ICO to a temp file and load it that way. Similar shenanigans are required for the ruby bindings.

Describe the solution you'd like

Add magic number to the coder. I think the two magic numbers are 00 00 01 00 (ICO) and 00 00 02 00 (CUR).

Thanks for all your hard work on ImageMagick, we use it regularly!

Describe alternatives you've considered

No response

Additional context

No response

@urban-warrior
Copy link
Member

Try this command:

identify icon:favicon.bogus

The format does not include a magic # field (see https://en.wikipedia.org/wiki/ICO_(file_format)), therefore, we cannot automatically detect the format other than relying on the .ico file extension.

@gurgeous
Copy link
Author

I think maybe there is a magic number, for two reasons:

  1. I am parsing the favicons of the top 1,000 alexa (tranco) sites. They all use 00 00 01 00 as the magic number. I haven't found any that don't contain that magic number.
  2. I see many references to an .ICO magic number online, just not on that wikipedia page. For example - https://fileformats.fandom.com/wiki/Icon http://fileformats.archiveteam.org/wiki/ICO https://www.daubnet.com/en/file-format-ico

Could we be mistaken?

@urban-warrior
Copy link
Member

urban-warrior commented Sep 18, 2021

The first two bytes are reserved-- meaning they are unreliable as they may change. Your link is also telling-- they discuss identification and they say "Note that this byte sequence is not very discriminating." For ImageMagick, we cannot rely on these bytes to identify ICO images s it will likely generate too many false positives. However, you could add the detection to your workflow and add the explicit icon:image.whatever to the ImageMagick command line.

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

No branches or pull requests

3 participants