mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-10-28 22:47:41 +03:00
Fix ZeroDivisionError in DdsImagePlugin (#9272)
This commit is contained in:
commit
148a19eee4
BIN
Tests/images/zero_mask_totals.dds
Normal file
BIN
Tests/images/zero_mask_totals.dds
Normal file
Binary file not shown.
|
|
@ -380,6 +380,11 @@ def test_palette() -> None:
|
||||||
assert_image_equal_tofile(im, "Tests/images/transparent.gif")
|
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:
|
def test_unsupported_header_size() -> None:
|
||||||
with pytest.raises(OSError, match="Unsupported header size 0"):
|
with pytest.raises(OSError, match="Unsupported header size 0"):
|
||||||
with Image.open(BytesIO(b"DDS " + b"\x00" * 4)):
|
with Image.open(BytesIO(b"DDS " + b"\x00" * 4)):
|
||||||
|
|
|
||||||
|
|
@ -333,6 +333,7 @@ class DdsImageFile(ImageFile.ImageFile):
|
||||||
format_description = "DirectDraw Surface"
|
format_description = "DirectDraw Surface"
|
||||||
|
|
||||||
def _open(self) -> None:
|
def _open(self) -> None:
|
||||||
|
assert self.fp is not None
|
||||||
if not _accept(self.fp.read(4)):
|
if not _accept(self.fp.read(4)):
|
||||||
msg = "not a DDS file"
|
msg = "not a DDS file"
|
||||||
raise SyntaxError(msg)
|
raise SyntaxError(msg)
|
||||||
|
|
@ -516,6 +517,8 @@ class DdsRgbDecoder(ImageFile.PyDecoder):
|
||||||
# Remove the zero padding, and scale it to 8 bits
|
# Remove the zero padding, and scale it to 8 bits
|
||||||
data += o8(
|
data += o8(
|
||||||
int(((masked_value >> mask_offsets[i]) / mask_totals[i]) * 255)
|
int(((masked_value >> mask_offsets[i]) / mask_totals[i]) * 255)
|
||||||
|
if mask_totals[i]
|
||||||
|
else 0
|
||||||
)
|
)
|
||||||
self.set_as_raw(data)
|
self.set_as_raw(data)
|
||||||
return -1, 0
|
return -1, 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user