Must explicitly check max rlevel on 1.x versions of library.

Otherwise it errors badly on 1.5, segfaults on 1.3.  Closes #106.
This commit is contained in:
John Evans 2013-08-20 22:10:38 -04:00
commit 009bd64772
2 changed files with 12 additions and 4 deletions

View file

@ -636,10 +636,18 @@ class Jp2k(Jp2kBox):
"""
self._subsampling_sanity_check()
if rlevel == -1:
# Get the lowest resolution thumbnail.
if rlevel != 0:
# Must check the specified rlevel against the maximum.
# OpenJPEG 1.3 will segfault if rlevel is too high.
codestream = self.get_codestream()
rlevel = codestream.segment[2].spcod[4]
max_rlevel = codestream.segment[2].spcod[4]
if rlevel == -1:
# -1 is shorthand for the largest rlevel
rlevel = max_rlevel
if rlevel < -1 or rlevel > max_rlevel:
msg = "rlevel must be in the range [-1, {0}] for this image."
msg = msg.format(max_rlevel)
raise IOError(msg)
with ExitStack() as stack:
# Set decoding parameters.

View file

@ -817,7 +817,7 @@ class TestJp2k15(unittest.TestCase):
def test_rlevel_too_high(self):
"""Should error out appropriately if reduce level too high"""
j = Jp2k(self.jp2file)
with self.assertRaises(ValueError):
with self.assertRaises(IOError):
j.read(rlevel=6)
def test_not_jpeg2000(self):