Skip to content

Commit 7780242

Browse files
Seek for start of object instead of calculating it (#806)
Fixes #803 Fixes #786
1 parent 0ee6704 commit 7780242

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

can/io/blf.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def __iter__(self):
175175

176176
if obj_type == LOG_CONTAINER:
177177
method, uncompressed_size = LOG_CONTAINER_STRUCT.unpack_from(obj_data)
178-
container_data = memoryview(obj_data)[LOG_CONTAINER_STRUCT.size :]
178+
container_data = obj_data[LOG_CONTAINER_STRUCT.size :]
179179
if method == NO_COMPRESSION:
180180
data = container_data
181181
elif method == ZLIB_DEFLATE:
@@ -220,6 +220,14 @@ def _parse_data(self, data):
220220
# Loop until a struct unpack raises an exception
221221
while True:
222222
self._pos = pos
223+
# Find next object after padding (depends on object type)
224+
try:
225+
pos = data.index(b"LOBJ", pos, pos + 8)
226+
except ValueError:
227+
if pos + 8 > max_pos:
228+
# Not enough data in container
229+
return
230+
raise BLFParseError("Could not find next object")
223231
header = unpack_obj_header_base(data, pos)
224232
# print(header)
225233
signature, _, header_version, obj_size, obj_type = header
@@ -228,9 +236,6 @@ def _parse_data(self, data):
228236

229237
# Calculate position of next object
230238
next_pos = pos + obj_size
231-
if obj_type != CAN_FD_MESSAGE_64:
232-
# Add padding bytes
233-
next_pos += obj_size % 4
234239
if next_pos > max_pos:
235240
# This object continues in the next container
236241
return

0 commit comments

Comments
 (0)