adamreeve / npTDMS

NumPy based Python module for reading TDMS files produced by LabView

Home Page:http://nptdms.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unpack requires a buffer 4 bytes

mdevore300 opened this issue · comments

My code using TDMS usually works fine. This file got interrupted and restarted with a different index number. But when you TDMSFile.open i get the unpack error

[nptdms.reader WARNING] Last segment of file has unknown size, will attempt to read to the end of the file
Traceback (most recent call last):

File "P:\Data by Fiscal Year\2022\ER\untitled0.py", line 31, in
tdms_file = TdmsFile.open("%s_0000.tdms" % name, raw_timestamps = True)

File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\tdms.py", line 87, in open
return TdmsFile(

File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\tdms.py", line 130, in init
self._read_file(self._reader, read_metadata_only, keep_open)

File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\tdms.py", line 226, in _read_file
tdms_reader.read_metadata(require_segment_indexes=keep_open)

File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\reader.py", line 87, in read_metadata
segment, properties = self._read_segment_metadata(

File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\reader.py", line 241, in _read_segment_metadata
properties = segment.read_segment_objects(

File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\tdms_segment.py", line 103, in read_segment_objects
raw_data_index_header = _struct_unpack(endianness + 'L', raw_data_index_header_bytes)[0]

error: unpack requires a buffer of 4 bytes

Hi, thanks for the bug report. It looks like the current logic for trying to read the last segment when writing was interrupted is assuming that the metadata was written okay and the data segment might be truncated, but doesn't account for cases where the segment metadata was not fully written.

Hi @mdevore300, I've just pushed a fix for this in #273, are you able to test with the current master branch of the code to see if your file can now be read?

Hmm okay I'm not sure what's going on there, are you able to provide a copy of the TDMS file that reproduces the error?

Sorry I'm guessing you've sent the files as email attachments but it doesn't look like GitHub adds them to the issue, you could send them directly to me at adreeve@gmail.com.

We've confirmed this is fixed but just updating the source files wasn't enough to pick up the fix. The fix has been released in version 1.5.0.

I'm using release 1.5.0, but still getting this same error:
line 103, in read_segment_objects raw_data_index_header = _struct_unpack(endianness + 'L', raw_data_index_header_bytes)[0] struct.error: unpack requires a buffer of 4 bytes

Hi @strontium5, are you able to provide an example file that reproduces the problem?

commented

I'm still having this issue with version 1.9.0.

Hi @ba05, if you can email me an example file that reproduces the error I can take a look.