Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions can/io/blf.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@ def _parse_data(self, data):
# Loop until a struct unpack raises an exception
while True:
self._pos = pos
#fix padding
if pos + obj_header_base_size > max_pos:
# This object continues in the next container
return
for i in range(4):
if data[pos+i:pos+i+4] == b"LOBJ":
break
pos += i
Comment on lines +223 to +230
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using the index method instead since it is implemented in optimized C. It should also handle the case when LOBJ is split up in two containers.

Suggested change
#fix padding
if pos + obj_header_base_size > max_pos:
# This object continues in the next container
return
for i in range(4):
if data[pos+i:pos+i+4] == b"LOBJ":
break
pos += i
# Find next object after padding (depends on object type)
try:
pos = data.index(b"LOBJ", pos, pos + 8)
except ValueError:
if pos + 8 > max_pos:
# Not enough data in container
return
raise BLFParseError("Could not find next object")

You would then also need to change line 178 to remove memoryview but that does not seem affect performance much.

header = unpack_obj_header_base(data, pos)
# print(header)
signature, _, header_version, obj_size, obj_type = header
Expand All @@ -228,9 +236,6 @@ def _parse_data(self, data):

# Calculate position of next object
next_pos = pos + obj_size
if obj_type != CAN_FD_MESSAGE_64:
# Add padding bytes
next_pos += obj_size % 4
if next_pos > max_pos:
# This object continues in the next container
return
Expand Down