Skip to content

Commit

Permalink
Raise an error for an invalid number of bands in FPX image
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 2, 2020
1 parent 8892aec commit 774e53b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Binary file added Tests/images/input_bw_five_bands.fpx
Binary file not shown.
6 changes: 6 additions & 0 deletions Tests/test_file_fpx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from PIL import Image

from .helper import PillowTestCase, unittest

try:
Expand All @@ -18,3 +20,7 @@ def test_invalid_file(self):
# Test a valid OLE file, but not an FPX file
ole_file = "Tests/images/test-ole-file.doc"
self.assertRaises(SyntaxError, FpxImagePlugin.FpxImageFile, ole_file)

def test_fpx_invalid_number_of_bands(self):
with self.assertRaisesRegex(IOError, "Invalid number of bands"):
Image.open("Tests/images/input_bw_five_bands.fpx")
5 changes: 4 additions & 1 deletion src/PIL/FpxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ def _open_index(self, index=1):
s = prop[0x2000002 | id]

colors = []
for i in range(i32(s, 4)):
bands = i32(s, 4)
if bands > 4:
raise IOError("Invalid number of bands")
for i in range(bands):
# note: for now, we ignore the "uncalibrated" flag
colors.append(i32(s, 8 + i * 4) & 0x7FFFFFFF)

Expand Down

0 comments on commit 774e53b

Please sign in to comment.