Skip to content

Commit e1e6fd4

Browse files
polyvertexDavid Cooper
authored and
David Cooper
committed
should fix #69
1 parent 3fa1fc0 commit e1e6fd4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

fitparse/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ def _parse_data_message(self, header):
319319
if field.components:
320320
for component in field.components:
321321
# Render its raw value
322-
cmp_raw_value = component.render(raw_value)
322+
try:
323+
cmp_raw_value = component.render(raw_value)
324+
except ValueError:
325+
continue
323326

324327
# Apply accumulated value
325328
if component.accumulate and cmp_raw_value is not None:

fitparse/records.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class SubField(FieldAndSubFieldBase):
299299
class DevField(FieldAndSubFieldBase):
300300
__slots__ = ('dev_data_index', 'def_num', 'type', 'name', 'units', 'native_field_num',
301301
# The rest of these are just to be compatible with Field objects. They're always None
302-
'scale', 'offset', 'components', 'subfields')
302+
'scale', 'offset', 'components', 'subfields')
303303
field_type = 'devfield'
304304

305305

@@ -318,6 +318,14 @@ def render(self, raw_value):
318318
# If it's a tuple, then it's a byte array and unpack it as such
319319
# (only type that uses this is compressed speed/distance)
320320
if isinstance(raw_value, tuple):
321+
# Profile.xls sometimes contains more components than the read raw
322+
# value is able to hold (typically the *event_timestamp_12* field in
323+
# *hr* messages).
324+
# This test allows to ensure *unpacked_num* is not right-shifted
325+
# more than necessary.
326+
if self.bit_offset and self.bit_offset >= len(raw_value) << 3:
327+
raise ValueError()
328+
321329
unpacked_num = 0
322330

323331
# Unpack byte array as little endian

0 commit comments

Comments
 (0)