diff --git a/Tests/test_file_xbm.py b/Tests/test_file_xbm.py index 2cf8d28e7e1..3a0729c5bce 100644 --- a/Tests/test_file_xbm.py +++ b/Tests/test_file_xbm.py @@ -110,6 +110,10 @@ def test_invalid_file() -> None: with pytest.raises(SyntaxError): XbmImagePlugin.XbmImageFile(invalid_file) + b = BytesIO(b"#define basic_width invalidwidth") + with pytest.raises(SyntaxError): + XbmImagePlugin.XbmImageFile(b) + def test_save_wrong_mode(tmp_path: Path) -> None: im = hopper() diff --git a/src/PIL/XbmImagePlugin.py b/src/PIL/XbmImagePlugin.py index 69ce54ebf19..e1818fac91c 100644 --- a/src/PIL/XbmImagePlugin.py +++ b/src/PIL/XbmImagePlugin.py @@ -80,7 +80,10 @@ def _open(self) -> None: if line.endswith(b"_bits[] = {"): offset = self.fp.tell() break - value = int(line.split().pop()) + try: + value = int(line.split().pop()) + except ValueError: + break if b"width " in line: width = value elif b"height " in line: