From: W. Trevor King Date: Sat, 21 Jul 2012 11:48:54 +0000 (-0400) Subject: Add 'not enough data...' errors to packed.load(). X-Git-Tag: v0.2~18 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1d1e8810333ab64d575bef2a723269ed42039083;p=igor.git Add 'not enough data...' errors to packed.load(). --- diff --git a/igor/packed.py b/igor/packed.py index 564725a..1b0fec5 100644 --- a/igor/packed.py +++ b/igor/packed.py @@ -55,6 +55,10 @@ def load(filename, strict=True, ignore_unknown=True): b = buffer(f.read(PackedFileRecordHeader.size)) if not b: 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') header = PackedFileRecordHeader.unpack_from(b) if header['version'] and not byte_order: @@ -70,6 +74,10 @@ def load(filename, strict=True, ignore_unknown=True): _LOG.debug( 'reordered version: {}'.format(header['version'])) 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( header['recordType'] & PACKEDRECTYPE_MASK, _UnknownRecord) _LOG.debug('the new record has type {} ({}).'.format(