Use _accept check in WebP _open (#9605)
This commit is contained in:
parent
ea5901535d
commit
3ce681240f
@ -49,6 +49,12 @@ class TestFileWebp:
|
||||
assert version is not None
|
||||
assert re.search(r"\d+\.\d+\.\d+$", version)
|
||||
|
||||
def test_invalid_file(self) -> None:
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
with pytest.raises(SyntaxError):
|
||||
WebPImagePlugin.WebPImageFile(invalid_file)
|
||||
|
||||
def test_read_rgb(self) -> None:
|
||||
"""
|
||||
Can we read a RGB mode WebP file without error?
|
||||
|
||||
@ -43,10 +43,15 @@ class WebPImageFile(ImageFile.ImageFile):
|
||||
__logical_frame = 0
|
||||
|
||||
def _open(self) -> None:
|
||||
assert self.fp is not None
|
||||
s = self.fp.read()
|
||||
if not _accept(s):
|
||||
msg = "not a WEBP file"
|
||||
raise SyntaxError(msg)
|
||||
|
||||
# Use the newer AnimDecoder API to parse the (possibly) animated file,
|
||||
# and access muxed chunks like ICC/EXIF/XMP.
|
||||
assert self.fp is not None
|
||||
self._decoder = _webp.WebPAnimDecoder(self.fp.read())
|
||||
self._decoder = _webp.WebPAnimDecoder(s)
|
||||
|
||||
# Get info from decoder
|
||||
self._size, self.info["loop"], bgcolor, self.n_frames, self.rawmode = (
|
||||
|
||||
Loading…
Reference in New Issue
Block a user