Skip to content

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

Closed

Description

@gurgeous

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

Activity

  1. urban-warrior commented on Sep 18, 2021

    @urban-warrior
    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.

  2. gurgeous commented on Sep 18, 2021

    @gurgeous
    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?

  3. urban-warrior commented on Sep 18, 2021

    @urban-warrior
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions