mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-23 13:44:47 +03:00
png: initialize _n_frames
- ImageFile._seek_check() will not EOF unless _n_frames is properly set for standard (non-animated) PNG images
This commit is contained in:
parent
8c9100e267
commit
dc56c6064f
|
@ -635,7 +635,10 @@ class TestFilePng:
|
||||||
|
|
||||||
def test_seek(self):
|
def test_seek(self):
|
||||||
with Image.open(TEST_PNG_FILE) as im:
|
with Image.open(TEST_PNG_FILE) as im:
|
||||||
|
assert im.n_frames == 1
|
||||||
im.seek(0)
|
im.seek(0)
|
||||||
|
with pytest.raises(EOFError):
|
||||||
|
im.seek(1)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(is_win32(), reason="Requires Unix or macOS")
|
@pytest.mark.skipif(is_win32(), reason="Requires Unix or macOS")
|
||||||
|
|
|
@ -636,7 +636,6 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
if self.fp.read(8) != _MAGIC:
|
if self.fp.read(8) != _MAGIC:
|
||||||
raise SyntaxError("not a PNG file")
|
raise SyntaxError("not a PNG file")
|
||||||
self.__fp = self.fp
|
self.__fp = self.fp
|
||||||
self.__frame = 0
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Parse headers up to the first IDAT or fDAT chunk
|
# Parse headers up to the first IDAT or fDAT chunk
|
||||||
|
@ -685,7 +684,12 @@ class PngImageFile(ImageFile.ImageFile):
|
||||||
else:
|
else:
|
||||||
self.__prepare_idat = length # used by load_prepare()
|
self.__prepare_idat = length # used by load_prepare()
|
||||||
|
|
||||||
if self._n_frames is not None:
|
if self._n_frames is None:
|
||||||
|
# standard PNG image, frame-related attributes still need to be
|
||||||
|
# initialized for seek()/_seek_check() to behave as expected
|
||||||
|
self.__frame = 0
|
||||||
|
self._n_frames = 1
|
||||||
|
else:
|
||||||
self._close_exclusive_fp_after_loading = False
|
self._close_exclusive_fp_after_loading = False
|
||||||
self.png.save_rewind()
|
self.png.save_rewind()
|
||||||
self.__rewind_idat = self.__prepare_idat
|
self.__rewind_idat = self.__prepare_idat
|
||||||
|
|
Loading…
Reference in New Issue
Block a user