Skip to content

Commit

Permalink
Fixed im.frombytes() for images with a zero dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 24, 2023
1 parent 5071692 commit 91f115b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,9 @@ def test_zero_tobytes(self, size):
def test_zero_frombytes(self, size):
Image.frombytes("RGB", size, b"")

im = Image.new("RGB", size)
im.frombytes(b"")

def test_has_transparency_data(self):
for mode in ("1", "L", "P", "RGB"):
im = Image.new(mode, (1, 1))
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ def frombytes(self, data, decoder_name="raw", *args):
but loads data into this image instead of creating a new image object.
"""

if self.width == 0 or self.height == 0:
return

# may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]
Expand Down

0 comments on commit 91f115b

Please sign in to comment.