mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 02:06:18 +03:00
Replaced primitive "magic number" inside of JpegImagePlugin._accept() function by more correct version.
This commit is contained in:
parent
d6be1331ce
commit
f99e0b824b
|
@ -706,6 +706,26 @@ class TestFileJpeg:
|
||||||
with Image.open("Tests/images/icc-after-SOF.jpg") as im:
|
with Image.open("Tests/images/icc-after-SOF.jpg") as im:
|
||||||
assert im.info["icc_profile"] == b"profile"
|
assert im.info["icc_profile"] == b"profile"
|
||||||
|
|
||||||
|
def test_reading_not_whole_file_for_define_it_type(self):
|
||||||
|
size = 1024 ** 2
|
||||||
|
buffer = BytesIO(b"\xFF" * size) # Many xFF bytes
|
||||||
|
buffer.max_pos = 0
|
||||||
|
orig_read = buffer.read
|
||||||
|
|
||||||
|
def read(n=-1):
|
||||||
|
res = orig_read(n)
|
||||||
|
buffer.max_pos = max(buffer.max_pos, buffer.tell())
|
||||||
|
return res
|
||||||
|
|
||||||
|
buffer.read = read
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
@pytest.mark.skipif(not is_win32(), reason="Windows only")
|
||||||
@skip_unless_feature("jpg")
|
@skip_unless_feature("jpg")
|
||||||
|
|
|
@ -323,7 +323,8 @@ MARKER = {
|
||||||
|
|
||||||
|
|
||||||
def _accept(prefix):
|
def _accept(prefix):
|
||||||
return prefix[0:1] == b"\377"
|
# Magic number was taken from https://en.wikipedia.org/wiki/JPEG
|
||||||
|
return prefix[0:3] == b"\xFF\xD8\xFF"
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
Loading…
Reference in New Issue
Block a user