mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Raise SyntaxError if data is not as expected
This commit is contained in:
parent
fbaaf3c19b
commit
efb9d503a7
|
@ -2,7 +2,7 @@ from io import BytesIO
|
|||
|
||||
import pytest
|
||||
|
||||
from PIL import Image
|
||||
from PIL import Image, XbmImagePlugin
|
||||
|
||||
from .helper import hopper
|
||||
|
||||
|
@ -63,6 +63,13 @@ def test_open_filename_with_underscore():
|
|||
assert im.size == (128, 128)
|
||||
|
||||
|
||||
def test_invalid_file():
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
with pytest.raises(SyntaxError):
|
||||
XbmImagePlugin.XbmImageFile(invalid_file)
|
||||
|
||||
|
||||
def test_save_wrong_mode(tmp_path):
|
||||
im = hopper()
|
||||
out = str(tmp_path / "temp.xbm")
|
||||
|
|
|
@ -52,18 +52,19 @@ class XbmImageFile(ImageFile.ImageFile):
|
|||
|
||||
m = xbm_head.match(self.fp.read(512))
|
||||
|
||||
if m:
|
||||
if not m:
|
||||
raise SyntaxError("not a XBM file")
|
||||
|
||||
xsize = int(m.group("width"))
|
||||
ysize = int(m.group("height"))
|
||||
xsize = int(m.group("width"))
|
||||
ysize = int(m.group("height"))
|
||||
|
||||
if m.group("hotspot"):
|
||||
self.info["hotspot"] = (int(m.group("xhot")), int(m.group("yhot")))
|
||||
if m.group("hotspot"):
|
||||
self.info["hotspot"] = (int(m.group("xhot")), int(m.group("yhot")))
|
||||
|
||||
self.mode = "1"
|
||||
self._size = xsize, ysize
|
||||
self.mode = "1"
|
||||
self._size = xsize, ysize
|
||||
|
||||
self.tile = [("xbm", (0, 0) + self.size, m.end(), None)]
|
||||
self.tile = [("xbm", (0, 0) + self.size, m.end(), None)]
|
||||
|
||||
|
||||
def _save(im, fp, filename):
|
||||
|
|
Loading…
Reference in New Issue
Block a user