diff --git a/src/PIL/BlpImagePlugin.py b/src/PIL/BlpImagePlugin.py index 2d03af9d7dd..e279322aadb 100644 --- a/src/PIL/BlpImagePlugin.py +++ b/src/PIL/BlpImagePlugin.py @@ -259,18 +259,21 @@ class BlpImageFile(ImageFile.ImageFile): def _open(self) -> None: self.magic = self.fp.read(4) + if self.magic not in (b"BLP1", b"BLP2"): + msg = f"Bad BLP magic {repr(self.magic)}" + raise BLPFormatError(msg) - self.fp.seek(5, os.SEEK_CUR) - (self._blp_alpha_depth,) = struct.unpack(" None: self.fd.seek(4) (self._blp_compression,) = struct.unpack(" None: assert im.palette is not None fp.write(struct.pack("