Skip to content

Commit cebaba1

Browse files
authored
Merge pull request #1 from radarhere/fix_jpeg_magic_number
Fix JPEG magic number
2 parents f99e0b8 + 65742cf commit cebaba1

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Tests/test_file_jpeg.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from io import BytesIO
44

55
import pytest
6-
from PIL import ExifTags, Image, ImageFile, JpegImagePlugin
6+
from PIL import ExifTags, Image, ImageFile, JpegImagePlugin, UnidentifiedImageError
77

88
from .helper import (
99
assert_image,
@@ -706,8 +706,8 @@ def test_icc_after_SOF(self):
706706
with Image.open("Tests/images/icc-after-SOF.jpg") as im:
707707
assert im.info["icc_profile"] == b"profile"
708708

709-
def test_reading_not_whole_file_for_define_it_type(self):
710-
size = 1024 ** 2
709+
def test_jpeg_magic_number(self):
710+
size = 4097
711711
buffer = BytesIO(b"\xFF" * size) # Many xFF bytes
712712
buffer.max_pos = 0
713713
orig_read = buffer.read
@@ -718,13 +718,11 @@ def read(n=-1):
718718
return res
719719

720720
buffer.read = read
721-
with pytest.raises(OSError):
721+
with pytest.raises(UnidentifiedImageError):
722722
Image.open(buffer)
723723

724-
# Only small part of file has been read.
725-
# The upper limit of max_pos (8Kb) was chosen experimentally
726-
# and increased approximately twice.
727-
assert 0 < buffer.max_pos < 8 * 1024
724+
# Assert the entire file has not been read
725+
assert 0 < buffer.max_pos < size
728726

729727

730728
@pytest.mark.skipif(not is_win32(), reason="Windows only")

0 commit comments

Comments
 (0)