Commit 1d1e8810 authored by W. Trevor King's avatar W. Trevor King
Browse files

Add 'not enough data...' errors to packed.load().

parent a2151cb1
...@@ -55,6 +55,10 @@ def load(filename, strict=True, ignore_unknown=True): ...@@ -55,6 +55,10 @@ def load(filename, strict=True, ignore_unknown=True):
b = buffer(f.read(PackedFileRecordHeader.size)) b = buffer(f.read(PackedFileRecordHeader.size))
if not b: if not b:
break break
if len(b) < PackedFileRecordHeader.size:
raise ValueError(
('not enough data for the next record header ({} < {})'
).format(len(b), PackedFileRecordHeader.size))
_LOG.debug('reading a new packed experiment file record') _LOG.debug('reading a new packed experiment file record')
header = PackedFileRecordHeader.unpack_from(b) header = PackedFileRecordHeader.unpack_from(b)
if header['version'] and not byte_order: if header['version'] and not byte_order:
...@@ -70,6 +74,10 @@ def load(filename, strict=True, ignore_unknown=True): ...@@ -70,6 +74,10 @@ def load(filename, strict=True, ignore_unknown=True):
_LOG.debug( _LOG.debug(
'reordered version: {}'.format(header['version'])) 'reordered version: {}'.format(header['version']))
data = buffer(f.read(header['numDataBytes'])) data = buffer(f.read(header['numDataBytes']))
if len(data) < header['numDataBytes']:
raise ValueError(
('not enough data for the next record ({} < {})'
).format(len(b), header['numDataBytes']))
record_type = _RECORD_TYPE.get( record_type = _RECORD_TYPE.get(
header['recordType'] & PACKEDRECTYPE_MASK, _UnknownRecord) header['recordType'] & PACKEDRECTYPE_MASK, _UnknownRecord)
_LOG.debug('the new record has type {} ({}).'.format( _LOG.debug('the new record has type {} ({}).'.format(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment