From bf18e5fe8bf837ba6756bef0384eae82504c7883 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 5 Sep 2025 20:03:31 +1000 Subject: [PATCH] Assert fp is not None --- Tests/test_file_cur.py | 1 + src/PIL/CurImagePlugin.py | 1 + 2 files changed, 2 insertions(+) diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py index dbf1b866d..ff82e2983 100644 --- a/Tests/test_file_cur.py +++ b/Tests/test_file_cur.py @@ -26,6 +26,7 @@ def test_invalid_file() -> None: no_cursors_file = "Tests/images/no_cursors.cur" cur = CurImagePlugin.CurImageFile(TEST_FILE) + assert cur.fp is not None cur.fp.close() with open(no_cursors_file, "rb") as cur.fp: with pytest.raises(TypeError): diff --git a/src/PIL/CurImagePlugin.py b/src/PIL/CurImagePlugin.py index 868ff50b5..9c188e084 100644 --- a/src/PIL/CurImagePlugin.py +++ b/src/PIL/CurImagePlugin.py @@ -38,6 +38,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile): format_description = "Windows Cursor" def _open(self) -> None: + assert self.fp is not None offset = self.fp.tell() # check magic