Fixed ZeroDivisionError

This commit is contained in:
Andrew Murray 2025-10-21 23:11:18 +11:00
parent 76f04b46c5
commit e1f4352ce9
3 changed files with 8 additions and 0 deletions

Binary file not shown.

View File

@ -380,6 +380,11 @@ def test_palette() -> None:
assert_image_equal_tofile(im, "Tests/images/transparent.gif")
def test_zero_mask_totals() -> None:
with Image.open("Tests/images/zero_mask_totals.dds") as im:
im.load()
def test_unsupported_header_size() -> None:
with pytest.raises(OSError, match="Unsupported header size 0"):
with Image.open(BytesIO(b"DDS " + b"\x00" * 4)):

View File

@ -333,6 +333,7 @@ class DdsImageFile(ImageFile.ImageFile):
format_description = "DirectDraw Surface"
def _open(self) -> None:
assert self.fp is not None
if not _accept(self.fp.read(4)):
msg = "not a DDS file"
raise SyntaxError(msg)
@ -516,6 +517,8 @@ class DdsRgbDecoder(ImageFile.PyDecoder):
# Remove the zero padding, and scale it to 8 bits
data += o8(
int(((masked_value >> mask_offsets[i]) / mask_totals[i]) * 255)
if mask_totals[i]
else 0
)
self.set_as_raw(data)
return -1, 0