Repository navigation
Compare icon suffix case-insensitively - #9521
Conversation
normalize_icon_type compares the file suffix against allowed_types, which is
always lower case ("ico", or "exe" and "ico"), but never lower-cases the
suffix it read. An icon named MyApp.ICO is therefore treated as the wrong
format.
Without Pillow that raises ValueError saying the file "is not in the correct
format" for a perfectly valid icon. With Pillow it silently round-trips the
icon through PIL and saves a new one, which drops the extra resolutions a
multi-size .ico carries.
CopyIcons in utils/win32/icon.py already compares the same suffix with
.lower(), five lines after calling this function.
|
Correcting something in my own description: I originally wrote that the PIL round trip "drops the extra resolutions a multi-size .ico carries". That is not what happens, and I have edited the body. Measured on the repo fixture: the source has sizes 16, 32, 48 and 256 in 56,493 bytes, and after an open-and-save through PIL it comes out with 16, 24, 32, 48, 64, 128 and 256 in 75,558 bytes. So PIL regenerates a fuller default set rather than losing sizes. The reason to avoid the round trip stands, it is just a different reason: the frames afterwards are resampled from the image PIL opened rather than the ones the author placed in the file, so hand-tuned small sizes are replaced by downscales, and the file is rewritten for no reason when it was already in the requested format. |
|
Thanks |
normalize_icon_typecompares the icon's suffix againstallowed_types, which is always lower case (("ico",), or("exe", "ico")fromCopyIcons), but it never lower-cases the suffix it read:So
MyApp.ICOis treated as the wrong format. What happens next depends on whether Pillow is installed:ValueErrorsaying the file "is not in the correct format" for an icon that is perfectly valid.tests/functional/data/set_icon/pyi_icon.ico: the original carries sizes 16, 32, 48 and 256 in 56,493 bytes, and the round-tripped copy comes out as 16, 24, 32, 48, 64, 128 and 256 in 75,558 bytes. The frames are regenerated by resampling rather than being the ones the author put in the file, so an icon with hand-tuned small sizes does not survive the trip intact.CopyIconsinPyInstaller/utils/win32/icon.pyalready compares the same suffix with.lower()five lines after calling this function, so the lower-case comparison is the intended behaviour, just missing here.The existing test iterates
["ico", "ICO"], but only over a mislabelled.png, which needs conversion in both cases. So the upper-case path passes today for the wrong reason. The new assertion uses the realpyi_icon.icofixture and fails without the change.flake8andyapf --diffare both clean.