From 2b9e230f76d28b868297039dfcbbeef98dca9ceb Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 24 Aug 2021 10:58:02 +0300 Subject: [PATCH 1/5] Fix ResourceWarning: unclosed file --- Tests/test_imagepalette.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/test_imagepalette.py b/Tests/test_imagepalette.py index 5a59b7799..475d249ed 100644 --- a/Tests/test_imagepalette.py +++ b/Tests/test_imagepalette.py @@ -16,10 +16,10 @@ def test_sanity(): def test_reload(): - im = Image.open("Tests/images/hopper.gif") - original = im.copy() - im.palette.dirty = 1 - assert_image_equal(im.convert("RGB"), original.convert("RGB")) + with Image.open("Tests/images/hopper.gif") as im: + original = im.copy() + im.palette.dirty = 1 + assert_image_equal(im.convert("RGB"), original.convert("RGB")) def test_getcolor(): From 474270fbd587cf303232dcde5bae350f2d34ce38 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 24 Aug 2021 11:03:10 +0300 Subject: [PATCH 2/5] Filter out UserWarning: Truncated File Read --- Tests/test_tiff_crashes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/test_tiff_crashes.py b/Tests/test_tiff_crashes.py index 6cdb8e44d..143765b8e 100644 --- a/Tests/test_tiff_crashes.py +++ b/Tests/test_tiff_crashes.py @@ -40,6 +40,7 @@ from .helper import on_ci ) @pytest.mark.filterwarnings("ignore:Possibly corrupt EXIF data") @pytest.mark.filterwarnings("ignore:Metadata warning") +@pytest.mark.filterwarnings("ignore:Truncated File Read") def test_tiff_crashes(test_file): try: with Image.open(test_file) as im: From 320ab8172e0d45b57a01c21cb0905abdf8593849 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 24 Aug 2021 11:19:45 +0300 Subject: [PATCH 3/5] Avoid DecompressionBombWarning: Image size (151587072 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. --- Tests/test_map.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/test_map.py b/Tests/test_map.py index 752c5f268..42f3447eb 100644 --- a/Tests/test_map.py +++ b/Tests/test_map.py @@ -24,11 +24,17 @@ def test_overflow(): def test_tobytes(): + # Note that this image triggers the decompression bomb warning: + max_pixels = Image.MAX_IMAGE_PIXELS + Image.MAX_IMAGE_PIXELS = None + # Previously raised an access violation on Windows with Image.open("Tests/images/l2rgb_read.bmp") as im: with pytest.raises((ValueError, MemoryError, OSError)): im.tobytes() + Image.MAX_IMAGE_PIXELS = max_pixels + @pytest.mark.skipif(sys.maxsize <= 2 ** 32, reason="Requires 64-bit system") def test_ysize(): From 2f8b3d0ff948942e609dd377c5ad1827c6830587 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 24 Aug 2021 11:20:09 +0300 Subject: [PATCH 4/5] Ignore new test_images file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5500ec037..790404535 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ docs/_build/ Tests/images/README.md Tests/images/crash_1.tif Tests/images/crash_2.tif +Tests/images/crash-81154a65438ba5aaeca73fd502fa4850fbde60f8.tif Tests/images/string_dimension.tiff Tests/images/jpeg2000 Tests/images/msp From d773fcd23d01c19af2cfbc280b8421ddfa0908e6 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 24 Aug 2021 11:33:43 +0300 Subject: [PATCH 5/5] Filter out UserWarning: Truncated File Read --- Tests/test_file_tiff.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index d5dda5799..236fcf445 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -698,6 +698,8 @@ class TestFileTiff: # Ignore this UserWarning which triggers for four tags: # "Possibly corrupt EXIF data. Expecting to read 50404352 bytes but..." @pytest.mark.filterwarnings("ignore:Possibly corrupt EXIF data") + # Ignore this UserWarning: + @pytest.mark.filterwarnings("ignore:Truncated File Read") @pytest.mark.skipif( not os.path.exists("Tests/images/string_dimension.tiff"), reason="Extra image files not installed",