From 3e9068a34564f33620b2a3b753d0b198af2a662b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 20 Jun 2020 09:48:55 +1000 Subject: [PATCH 1/3] Decreased length of test image data --- Tests/test_file_jpeg.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 7702d35b5..25c1726c1 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -707,7 +707,7 @@ class TestFileJpeg: assert im.info["icc_profile"] == b"profile" def test_reading_not_whole_file_for_define_it_type(self): - size = 1024 ** 2 + size = 4097 buffer = BytesIO(b"\xFF" * size) # Many xFF bytes buffer.max_pos = 0 orig_read = buffer.read @@ -721,10 +721,8 @@ class TestFileJpeg: with pytest.raises(OSError): Image.open(buffer) - # Only small part of file has been read. - # The upper limit of max_pos (8Kb) was chosen experimentally - # and increased approximately twice. - assert 0 < buffer.max_pos < 8 * 1024 + # Assert the entire file has not been read + assert 0 < buffer.max_pos < size @pytest.mark.skipif(not is_win32(), reason="Windows only") From abbc890b205dca4040a6ac144cf17997f1ab0e9e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 20 Jun 2020 09:51:48 +1000 Subject: [PATCH 2/3] Replaced OSError with more specific UnidentifiedImageError --- Tests/test_file_jpeg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 25c1726c1..9b7c4dcea 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -3,7 +3,7 @@ import re from io import BytesIO import pytest -from PIL import ExifTags, Image, ImageFile, JpegImagePlugin +from PIL import ExifTags, Image, ImageFile, JpegImagePlugin, UnidentifiedImageError from .helper import ( assert_image, @@ -718,7 +718,7 @@ class TestFileJpeg: return res buffer.read = read - with pytest.raises(OSError): + with pytest.raises(UnidentifiedImageError): Image.open(buffer) # Assert the entire file has not been read From 65742cfc9558eebb52e13087c2c06740478586d1 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 20 Jun 2020 09:57:51 +1000 Subject: [PATCH 3/3] Renamed test --- Tests/test_file_jpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 9b7c4dcea..5573086cb 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -706,7 +706,7 @@ class TestFileJpeg: with Image.open("Tests/images/icc-after-SOF.jpg") as im: assert im.info["icc_profile"] == b"profile" - def test_reading_not_whole_file_for_define_it_type(self): + def test_jpeg_magic_number(self): size = 4097 buffer = BytesIO(b"\xFF" * size) # Many xFF bytes buffer.max_pos = 0