Raise an error for an invalid number of bands in FPX image

This commit is contained in:
Andrew Murray 2020-01-01 16:07:03 +11:00
parent ac4b7082c1
commit 138bd714f5
3 changed files with 10 additions and 1 deletions

Binary file not shown.

View File

@ -1,5 +1,7 @@
import unittest
from PIL import Image
from .helper import PillowTestCase
try:
@ -20,3 +22,7 @@ class TestFileFpx(PillowTestCase):
# 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")

View File

@ -97,7 +97,10 @@ class FpxImageFile(ImageFile.ImageFile):
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)