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:
parent
08578115f6
commit
009bd64772
2 changed files with 12 additions and 4 deletions
|
|
@ -636,10 +636,18 @@ class Jp2k(Jp2kBox):
|
||||||
"""
|
"""
|
||||||
self._subsampling_sanity_check()
|
self._subsampling_sanity_check()
|
||||||
|
|
||||||
if rlevel == -1:
|
if rlevel != 0:
|
||||||
# Get the lowest resolution thumbnail.
|
# Must check the specified rlevel against the maximum.
|
||||||
|
# OpenJPEG 1.3 will segfault if rlevel is too high.
|
||||||
codestream = self.get_codestream()
|
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:
|
with ExitStack() as stack:
|
||||||
# Set decoding parameters.
|
# Set decoding parameters.
|
||||||
|
|
|
||||||
|
|
@ -817,7 +817,7 @@ class TestJp2k15(unittest.TestCase):
|
||||||
def test_rlevel_too_high(self):
|
def test_rlevel_too_high(self):
|
||||||
"""Should error out appropriately if reduce level too high"""
|
"""Should error out appropriately if reduce level too high"""
|
||||||
j = Jp2k(self.jp2file)
|
j = Jp2k(self.jp2file)
|
||||||
with self.assertRaises(ValueError):
|
with self.assertRaises(IOError):
|
||||||
j.read(rlevel=6)
|
j.read(rlevel=6)
|
||||||
|
|
||||||
def test_not_jpeg2000(self):
|
def test_not_jpeg2000(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue