Should not error out if rreq mask length is not 1, 2, 4, or 8. #141
This is a hot fix, bumping to 0.5.10.
This commit is contained in:
parent
3299c2e562
commit
dd72595733
4 changed files with 78 additions and 6 deletions
|
|
@ -1465,13 +1465,24 @@ class ReaderRequirementsBox(Jp2kBox):
|
|||
# Decodes Completely Mask
|
||||
read_buffer = fptr.read(2 * mask_length)
|
||||
|
||||
fuam = dcm = standard_flag = standard_mask = []
|
||||
vendor_feature = vendor_mask = []
|
||||
|
||||
# The mask length tells us the format string to use when unpacking
|
||||
# from the buffer read from file.
|
||||
mask_format = {1: 'B', 2: 'H', 4: 'I'}[mask_length]
|
||||
fuam, dcm = struct.unpack('>' + mask_format * 2, read_buffer)
|
||||
try:
|
||||
mask_format = {1: 'B', 2: 'H', 4: 'I', 8: 'Q'}[mask_length]
|
||||
fuam, dcm = struct.unpack('>' + mask_format * 2, read_buffer)
|
||||
standard_flag, standard_mask = _parse_standard_flag(fptr,
|
||||
mask_length)
|
||||
vendor_feature, vendor_mask = _parse_vendor_features(fptr,
|
||||
mask_length)
|
||||
|
||||
standard_flag, standard_mask = _parse_standard_flag(fptr, mask_length)
|
||||
vendor_feature, vendor_mask = _parse_vendor_features(fptr, mask_length)
|
||||
except KeyError:
|
||||
msg = 'The ReaderRequirements box (rreq) has a mask length of {0} '
|
||||
msg += 'bytes, but only values of 1, 2, 4, or 8 are supported. '
|
||||
msg += 'The box contents will not be interpreted.'
|
||||
warnings.warn(msg.format(mask_length), UserWarning)
|
||||
|
||||
box = ReaderRequirementsBox(fuam, dcm, standard_flag, standard_mask,
|
||||
vendor_feature, vendor_mask,
|
||||
|
|
|
|||
61
glymur/test/test_jp2box_jpx.py
Normal file
61
glymur/test/test_jp2box_jpx.py
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test suite specifically targeting JPX box layout.
|
||||
"""
|
||||
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import warnings
|
||||
import xml.etree.cElementTree as ET
|
||||
|
||||
if sys.hexversion < 0x02070000:
|
||||
import unittest2 as unittest
|
||||
else:
|
||||
import unittest
|
||||
|
||||
import glymur
|
||||
from glymur import Jp2k
|
||||
from glymur.jp2box import ReaderRequirementsBox
|
||||
|
||||
|
||||
@unittest.skipIf(sys.hexversion < 0x03000000, "Warning assert on 2.x.")
|
||||
@unittest.skipIf(os.name == "nt", "Temporary file issue on window.")
|
||||
class TestReaderRequirements(unittest.TestCase):
|
||||
"""Test suite for XML boxes."""
|
||||
|
||||
def setUp(self):
|
||||
self.jp2file = glymur.data.nemo()
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_mask_length_is_3(self):
|
||||
"""The standard says that the mask length should be 1, 2, 4, or 8."""
|
||||
# Rewrite nemo to include this kind of rreq box.
|
||||
with tempfile.NamedTemporaryFile(suffix=".jpx") as tfile:
|
||||
with open(self.jp2file, 'rb') as nemof:
|
||||
# Read the jP and ftyp boxes as-is.
|
||||
write_buffer = nemof.read(32)
|
||||
tfile.write(write_buffer)
|
||||
|
||||
# Fake a rreq box with ML = 3.
|
||||
write_buffer = struct.pack('>I4sB', 74, b'rreq', 3)
|
||||
tfile.write(write_buffer)
|
||||
|
||||
# pad the rest with zeros
|
||||
write_buffer = struct.pack('>65s', b'\x00' * 65)
|
||||
tfile.write(write_buffer)
|
||||
|
||||
# Write the rest of nemo.
|
||||
tfile.write(nemof.read())
|
||||
tfile.flush()
|
||||
|
||||
with self.assertWarns(UserWarning):
|
||||
j = Jp2k(tfile.name)
|
||||
self.assertEqual(j.box[2].box_id, 'rreq')
|
||||
self.assertEqual(type(j.box[2]),
|
||||
glymur.jp2box.ReaderRequirementsBox)
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ from .lib import openjp2 as opj2
|
|||
|
||||
# Do not change the format of this next line! Doing so risks breaking
|
||||
# setup.py
|
||||
version = "0.5.9"
|
||||
version = "0.5.10"
|
||||
_sv = LooseVersion(version)
|
||||
version_tuple = _sv.version
|
||||
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -7,7 +7,7 @@ kwargs = {'name': 'Glymur',
|
|||
'description': 'Tools for accessing JPEG2000 files',
|
||||
'long_description': open('README.md').read(),
|
||||
'author': 'John Evans',
|
||||
'author_email': 'john.g.evans.ne at gmail dot com',
|
||||
'author_email': 'john.g.evans.ne@gmail.com',
|
||||
'url': 'https://github.com/quintusdias/glymur',
|
||||
'packages': ['glymur', 'glymur.data', 'glymur.test', 'glymur.lib',
|
||||
'glymur.lib.test'],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue