Repository navigation
Add lenient mode to ICO decoder - #3001
Conversation
|
I also tested your example file in a few programs, and the results are interesting:
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.
What do you think? |
|
@RunDevelopment thank you for the thorough review and for testing this with different programs! :) I've updated my changes to make the PNG path lenient as well. Though I decided not to enforce strict dimension limits for PNGs in lenient mode since it's lenient mode, and this matches the behavior of the BMP decoder which doesn't enforce size restrictions either. I also found that there exist some tools like https://redketchup.io/icon-converter, where it is possible to generate custom ICO images containing 512x512 PNGs. So even if those images are rare, they still might exist in the wild, and with no hard dimension restrictions the rust decoder can decode them as well |
|
I think you're right. Basically all Microsoft products support ICOs with image data >256x256. I tested this with the tool you linked to create some 1024x1024 icos. So I think it's okay to allow them in lenient mode. |
197g
left a comment
There was a problem hiding this comment.
It seems fine to me to use the interpretation that the ICO meta entry's dimensions is mainly used for selection and in a lenient decoding we should probably always use the factual underlying PNG. For Bitmaps.. have a read: https://learn.microsoft.com/en-us/previous-versions/ms997538(v=msdn.10) and let me know your interpretation of it.
Only the following members are used: biSize, biWidth, biHeight, biPlanes, biBitCount, biSizeImage. All other members must be 0. The biHeight member specifies the combined height of the XOR and AND masks.
It implies that the inner bitmap may store multiple planes of image data that are post-processed to form the actual color data for the ICO, right? More context, well I'm using the term more loosely as it is very little, in Raymond Chen's post.
According to the docs of |
Co-authored-by: Michael Schmidt <msrd0000@gmail.com>
RunDevelopment
left a comment
There was a problem hiding this comment.
LGTM; Thank you, @mpospelova!
Could you please resolve the merge conflict?
Add lenient mode to ICO decoder
Ignore dimension mismatch in lenient mode and decode the image using the embedded image's dimensions