@@ -189,13 +189,13 @@ def __iter__(self):
189189 def _parse_container (self , data ):
190190 if self ._tail :
191191 data = b"" .join ((self ._tail , data ))
192- self ._pos = 0
193192 try :
194193 yield from self ._parse_data (data )
195194 except struct .error :
196- # Container data exhausted
197- # Save the remaining data that could not be processed
198- self ._tail = data [self ._pos :]
195+ # There was not enough data in the container to unpack a struct
196+ pass
197+ # Save the remaining data that could not be processed
198+ self ._tail = data [self ._pos :]
199199
200200 def _parse_data (self , data ):
201201 """Optimized inner loop by making local copies of global variables
@@ -213,12 +213,14 @@ def _parse_data(self, data):
213213 unpack_can_error_ext = CAN_ERROR_EXT_STRUCT .unpack_from
214214
215215 start_timestamp = self .start_timestamp
216+ max_pos = len (data )
216217 pos = 0
217218
218219 # Loop until a struct unpack raises an exception
219220 while True :
220221 self ._pos = pos
221222 header = unpack_obj_header_base (data , pos )
223+ # print(header)
222224 signature , _ , header_version , obj_size , obj_type = header
223225 if signature != b"LOBJ" :
224226 raise BLFParseError ()
@@ -228,6 +230,9 @@ def _parse_data(self, data):
228230 if obj_type != CAN_FD_MESSAGE_64 :
229231 # Add padding bytes
230232 next_pos += obj_size % 4
233+ if next_pos > max_pos :
234+ # This object continues in the next container
235+ return
231236 pos += obj_header_base_size
232237
233238 # Read rest of header
0 commit comments