Skip to content

Commit c807f65

Browse files
authored
Clear C image when MPO frame image size changes (#9208)
2 parents 2275993 + ce8d054 commit c807f65

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Tests/images/frame_size.mpo

14.2 KB
Binary file not shown.
-117 KB
Binary file not shown.

Tests/test_file_mpo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ def test_exif(test_file: str) -> None:
104104

105105

106106
def test_frame_size() -> None:
107-
# This image has been hexedited to contain a different size
108-
# in the SOF marker of the second frame
109-
with Image.open("Tests/images/sugarshack_frame_size.mpo") as im:
110-
assert im.size == (640, 480)
107+
with Image.open("Tests/images/frame_size.mpo") as im:
108+
assert im.size == (56, 70)
109+
im.load()
111110

112111
im.seek(1)
113-
assert im.size == (680, 480)
112+
assert im.size == (349, 434)
113+
im.load()
114114

115115
im.seek(0)
116-
assert im.size == (640, 480)
116+
assert im.size == (56, 70)
117117

118118

119119
def test_ignore_frame_size() -> None:

src/PIL/JpegImagePlugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ def SOF(self: JpegImageFile, marker: int) -> None:
193193
n = i16(self.fp.read(2)) - 2
194194
s = ImageFile._safe_read(self.fp, n)
195195
self._size = i16(s, 3), i16(s, 1)
196+
if self._im is not None and self.size != self.im.size:
197+
self._im = None
196198

197199
self.bits = s[0]
198200
if self.bits != 8:

0 commit comments

Comments
 (0)