-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unpack requires a buffer 4 bytes #272
Comments
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? |
Hi Adam,
I changed the code in the three files, but it is still not working
tdms_file = TdmsFile.open("{}_0000.tdms" .format(name), raw_timestamps = True)
[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 "<ipython-input-2-708a9fc280eb>", line 1, in <module>
tdms_file = TdmsFile.open("{}_0000.tdms" .format(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 129, in read_segment_objects
object_properties = self._read_object_properties(file, endianness)
File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\tdms_segment.py", line 219, in _read_object_properties
num_properties = _struct_unpack(endianness + 'L', num_properties_bytes)[0]
error: unpack requires a buffer of 4 bytes
From: Adam Reeve ***@***.***>
Sent: Sunday, June 12, 2022 3:57 PM
To: adamreeve/npTDMS ***@***.***>
Cc: DeVore II, Michael Alan ***@***.***>; Mention ***@***.***>
Subject: [EXTERNAL] Re: [adamreeve/npTDMS] unpack requires a buffer 4 bytes (Issue #272)
Hi @mdevore300<https://urldefense.com/v3/__https:/github.com/mdevore300__;!!Bt8fGhp8LhKGRg!G63lnRfXPDtD2k1Y2aWaQHYmsFrvaNeft-H3v6jUosCkqOcMMgXDOimDxoZ8oCJQ7uGbld0dV-YiNMTh-h2v4j1J4avGkw$>, I've just pushed a fix for this in #273<https://urldefense.com/v3/__https:/github.com/adamreeve/npTDMS/pull/273__;!!Bt8fGhp8LhKGRg!G63lnRfXPDtD2k1Y2aWaQHYmsFrvaNeft-H3v6jUosCkqOcMMgXDOimDxoZ8oCJQ7uGbld0dV-YiNMTh-h2v4j1_G2B3Eg$>, are you able to test with the current master branch of the code to see if your file can now be read?
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/adamreeve/npTDMS/issues/272*issuecomment-1153302564__;Iw!!Bt8fGhp8LhKGRg!G63lnRfXPDtD2k1Y2aWaQHYmsFrvaNeft-H3v6jUosCkqOcMMgXDOimDxoZ8oCJQ7uGbld0dV-YiNMTh-h2v4j0LDStBvQ$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AZNQDHLRCYCMWX7RCKOZY3TVOZMJPANCNFSM5XOXAFCA__;!!Bt8fGhp8LhKGRg!G63lnRfXPDtD2k1Y2aWaQHYmsFrvaNeft-H3v6jUosCkqOcMMgXDOimDxoZ8oCJQ7uGbld0dV-YiNMTh-h2v4j23pkat0Q$>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
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? |
Sure.
From: Adam Reeve ***@***.***>
Sent: Wednesday, June 15, 2022 12:53 PM
To: adamreeve/npTDMS ***@***.***>
Cc: DeVore II, Michael Alan ***@***.***>; Mention ***@***.***>
Subject: [EXTERNAL] Re: [adamreeve/npTDMS] unpack requires a buffer 4 bytes (Issue #272)
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?
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/adamreeve/npTDMS/issues/272*issuecomment-1156815071__;Iw!!Bt8fGhp8LhKGRg!EV-rEd-zDgUV1nRsFavSJXxa0m4jaMyTQ90cBPn37agiCMVAImPQEdZawMapU-pnX1KF57zQ4OE7swWRhewoosjbdPT2Gw$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AZNQDHJXP6MJSFEZROU2RELVPIRANANCNFSM5XOXAFCA__;!!Bt8fGhp8LhKGRg!EV-rEd-zDgUV1nRsFavSJXxa0m4jaMyTQ90cBPn37agiCMVAImPQEdZawMapU-pnX1KF57zQ4OE7swWRhewooshVJzkdXQ$>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
Also got this error with a different file requiring 20 bytes
Traceback (most recent call last):
File "<ipython-input-36-975b851b8107>", line 1, in <module>
test = TdmsFile.open("2PMR060622_0000.tdms")
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 235, in _read_segment_metadata
(position, toc_mask, data_position, next_segment_pos, segment_incomplete) = self._read_lead_in(
File "C:\Users\284210\Anaconda3\lib\site-packages\nptdms-1.3.1-py3.8.egg\nptdms\reader.py", line 268, in _read_lead_in
(version, next_segment_offset, raw_data_offset) = _struct_unpack(endianness + 'lQQ', lead_in_bytes[8:28])
error: unpack requires a buffer of 20 bytes
From: Adam Reeve ***@***.***>
Sent: Wednesday, June 15, 2022 12:53 PM
To: adamreeve/npTDMS ***@***.***>
Cc: DeVore II, Michael Alan ***@***.***>; Mention ***@***.***>
Subject: [EXTERNAL] Re: [adamreeve/npTDMS] unpack requires a buffer 4 bytes (Issue #272)
Reopened #272<https://urldefense.com/v3/__https:/github.com/adamreeve/npTDMS/issues/272__;!!Bt8fGhp8LhKGRg!DefUfUWxohNFHVp4obIUrDPkB3tOpiWusqruxGtKlmNN2j_H-XkKQ4wdIIGM6DeqBEC7PD5OojOBqDyT_18OqDiB43IhCg$>.
—
Reply to this email directly, view it on GitHub<https://urldefense.com/v3/__https:/github.com/adamreeve/npTDMS/issues/272*event-6815372418__;Iw!!Bt8fGhp8LhKGRg!DefUfUWxohNFHVp4obIUrDPkB3tOpiWusqruxGtKlmNN2j_H-XkKQ4wdIIGM6DeqBEC7PD5OojOBqDyT_18OqDgVnvG-0g$>, or unsubscribe<https://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AZNQDHOKV3VSFVSJHQGSMFDVPIRARANCNFSM5XOXAFCA__;!!Bt8fGhp8LhKGRg!DefUfUWxohNFHVp4obIUrDPkB3tOpiWusqruxGtKlmNN2j_H-XkKQ4wdIIGM6DeqBEC7PD5OojOBqDyT_18OqDgKOLtOQg$>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
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: |
Hi @strontium5, are you able to provide an example file that reproduces the problem? |
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. |
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
The text was updated successfully, but these errors were encountered: