diff --git a/Tests/images/ico1both.ico b/Tests/images/ico1both.ico new file mode 100644 index 000000000..d0c95b70c Binary files /dev/null and b/Tests/images/ico1both.ico differ diff --git a/Tests/images/ico1device_dependent.ico b/Tests/images/ico1device_dependent.ico new file mode 100644 index 000000000..8a6a9f2e0 Binary files /dev/null and b/Tests/images/ico1device_dependent.ico differ diff --git a/Tests/images/ico1.ico b/Tests/images/ico1device_independent.ico similarity index 100% rename from Tests/images/ico1.ico rename to Tests/images/ico1device_independent.ico diff --git a/Tests/test_file_ico.py b/Tests/test_file_ico.py index 7c5dd0739..e4b8bd62a 100644 --- a/Tests/test_file_ico.py +++ b/Tests/test_file_ico.py @@ -229,10 +229,20 @@ def test_draw_reloaded(tmp_path): assert_image_equal_tofile(im, "Tests/images/hopper_draw.ico") -def test_ico1_open(): - with Image.open("Tests/images/ico1.ico") as im: +@pytest.mark.parametrize( + "test_image_path", + ( + "Tests/images/ico1device_independent.ico", + "Tests/images/ico1device_dependent.ico", + "Tests/images/ico1both.ico", + ), +) +def test_ico1_open(test_image_path): + with Image.open(test_image_path) as im: assert_image_equal_tofile(im, "Tests/images/ico1.png") + +def test_ico1_invalid_file(): with open("Tests/images/flower.jpg", "rb") as fp: with pytest.raises(SyntaxError): IcoImagePlugin.Ico1ImageFile(fp) diff --git a/docs/handbook/image-file-formats.rst b/docs/handbook/image-file-formats.rst index d92978c4a..ca980a764 100644 --- a/docs/handbook/image-file-formats.rst +++ b/docs/handbook/image-file-formats.rst @@ -345,7 +345,8 @@ The :py:meth:`~PIL.Image.Image.save` method can take the following keyword argum ICO1 ^^^^ -Pillow also reads and writes device-independent Windows 1.0 icons. +Pillow also reads Windows 1.0 icons in all three formats ("Device-Independent", +"Device-Dependent" and "Both"), and writes them in "Device-Independent" format. .. versionadded:: 10.1.0 diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py index 534708024..d1a88f396 100644 --- a/src/PIL/IcoImagePlugin.py +++ b/src/PIL/IcoImagePlugin.py @@ -349,7 +349,7 @@ class IcoImageFile(ImageFile.ImageFile): def _ico1_accept(prefix): - return prefix[:2] == b"\1\0" + return prefix[0] == 1 and prefix[1] in (0, 1, 2) class Ico1ImageFile(ImageFile.ImageFile):