danielhrisca / asammdf

Fast Python reader and editor for ASAM MDF / MF4 (Measurement Data Format) files
GNU Lesser General Public License v3.0
611 stars 216 forks source link

Fail to open Unfinilized MF4 with specific data #1014

Open david32 opened 1 month ago

david32 commented 1 month ago

Python version

Exist in all versions

Code

MDF version

4.1

Code snippet

mdf_v4 _finilize() method

Traceback

Traceback (most recent call last):
  File "D:\Python_Projects\asammdf\src\asammdf\gui\utils.py", line 403, in run
    self.output = self._target(*self._args, **self._kwargs)
  File "D:\Python_Projects\asammdf\src\asammdf\mdf.py", line 332, in __init__
    self._mdf = mdf_v4.MDF4(name, channels=channels, **kwargs)
  File "D:\Python_Projects\asammdf\src\asammdf\blocks\mdf_v4.py", line 373, in __init__
    self._read(mapped=False, progress=progress)
  File "D:\Python_Projects\asammdf\src\asammdf\blocks\mdf_v4.py", line 479, in _read
    self._finalize()
  File "D:\Python_Projects\asammdf\src\asammdf\blocks\mdf_v4.py", line 10084, in _finalize
    group = DataGroup(address=dg_addr, stream=stream, mapped=mapped)
  File "D:\Python_Projects\asammdf\src\asammdf\blocks\v4_blocks.py", line 4720, in __init__
    self.comment = get_text_v4(self.comment_addr, stream, mapped=mapped)
  File "D:\Python_Projects\asammdf\src\asammdf\blocks\utils.py", line 350, in get_text_v4
    block_id, size = BLK_COMMON_u(stream.read(24))
struct.error: unpack requires a buffer of 24 bytes 

Description

This was encountered using one of the great CSS Dataloggers but it's possible to replicate easily: Create an Unfinalized MF4 file with data that contains "##DG " in the data field. Try to open the file - get exception. Caused by software looping over all ##DG occurences even if there is no pointer to one.

danielhrisca commented 1 month ago

@david32 please try the development branch code

david32 commented 1 month ago

yes it does. Why would you prefer this solution to iterating over pointers?