Add 'not enough data...' errors to packed.load().
authorW. Trevor King <wking@tremily.us>
Sat, 21 Jul 2012 11:48:54 +0000 (07:48 -0400)
committerW. Trevor King <wking@tremily.us>
Sat, 21 Jul 2012 11:48:54 +0000 (07:48 -0400)
igor/packed.py

index 564725aabbb9df7177c02a31aaa6afea0474b50c..1b0fec5f582f471d6f1ef9fc253324ad4da54fce 100644 (file)
@@ -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(