mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Raise an error for an invalid number of bands in FPX image
This commit is contained in:
parent
ac4b7082c1
commit
138bd714f5
BIN
Tests/images/input_bw_five_bands.fpx
Normal file
BIN
Tests/images/input_bw_five_bands.fpx
Normal file
Binary file not shown.
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user