From b479ece7b488e236418014f9dd1ff5db1877b522 Mon Sep 17 00:00:00 2001 From: John Evans Date: Wed, 12 Mar 2014 10:10:38 -0400 Subject: [PATCH] Bring back check for bad rlevel. #159 OpenJPEG 1.5 needs the protection, it would seem. --- glymur/jp2k.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 3467426..7a513fe 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -772,6 +772,19 @@ class Jp2k(Jp2kBox): """ self._subsampling_sanity_check() + # Must check the specified rlevel against the maximum. + if rlevel != 0: + # Must check the specified rlevel against the maximum. + codestream = self.get_codestream() + max_rlevel = codestream.segment[2].spcod[4] + if rlevel == -1: + # -1 is shorthand for the largest rlevel + rlevel = max_rlevel + elif 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: try: # Set decoding parameters.