mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-10-27 22:21:33 +03:00
Fixed ZeroDivisionError
This commit is contained in:
parent
76f04b46c5
commit
e1f4352ce9
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")
|
||||
|
||||
|
||||
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)):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user