Skip to content

Commit

Permalink
Fixed Image.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 d05ff50 commit 5071692
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,10 @@ def test_zero_tobytes(self, size):
im = Image.new("RGB", size)
assert im.tobytes() == b""

@pytest.mark.parametrize("size", ((1, 0), (0, 1), (0, 0)))
def test_zero_frombytes(self, size):
Image.frombytes("RGB", size, b"")

def test_has_transparency_data(self):
for mode in ("1", "L", "P", "RGB"):
im = Image.new(mode, (1, 1))
Expand Down
15 changes: 8 additions & 7 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2967,15 +2967,16 @@ def frombytes(mode, size, data, decoder_name="raw", *args):

_check_size(size)

# may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]
im = new(mode, size)
if im.width != 0 and im.height != 0:
# may pass tuple instead of argument list
if len(args) == 1 and isinstance(args[0], tuple):
args = args[0]

if decoder_name == "raw" and args == ():
args = mode
if decoder_name == "raw" and args == ():
args = mode

im = new(mode, size)
im.frombytes(data, decoder_name, args)
im.frombytes(data, decoder_name, args)
return im


Expand Down

0 comments on commit 5071692

Please sign in to comment.