From 1d1e8810333ab64d575bef2a723269ed42039083 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 21 Jul 2012 07:48:54 -0400 Subject: [PATCH] Add 'not enough data...' errors to packed.load(). --- igor/packed.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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( -- 2.26.2