koodaamo / tnefparse

a TNEF decoding library written in python, without external dependencies
GNU Lesser General Public License v3.0
49 stars 37 forks source link

crash with message "struct.error: unpack_from requires a buffer of at least 4 bytes" #68

Closed Sam-Gracy closed 4 years ago

Sam-Gracy commented 4 years ago

Hi,

When I tr to extract the winmail.dat using the TNEF library I am seeing the below crash. Could you please help me to have a look.

 TNEFObject = TNEF(open(filename, 'rb').read(), do_checksum=True) 
  File "/usr/local/lib/python3.7/dist-packages/tnefparse/tnef.py", line 201, in __init__
    self.signature = uint32(data)
  File "/usr/local/lib/python3.7/dist-packages/tnefparse/util.py", line 20, in unpack
    return call(byte_arr, offset)[0]
struct.error: unpack_from requires a buffer of at least 4 bytes
jugmac00 commented 4 years ago

Hi @Sam-Gracy while I am pretty sure, I am not familiar enough with the code base in order to fix your problem, let me try to ask the right questions, so e.g. @petri is maybe able to help you.

a) I edited your issue and surrounded the code with three backticks - so GitHub marks this as code block and makes it easier to read for all of us b) When I have a look at the current master branch, the line numbers do not match with your report. Which version of tnefparse did you use? Could you try either the latest version from PyPi or even the one from the master branch? Although I have not found closed issues with this problem, maybe your problem has been fixed already. c) Would it be possible to provide the problematic file? Or is it confidential?

Sam-Gracy commented 4 years ago

Thank you Jugmac00.

I am using the latest code and I can see the exact line numbers in file https://github.com/koodaamo/tnefparse/blob/master/tnefparse/util.py

image

I am sorry, I am not be able to share that file. If I able to reproduce it with any test file, I'll share it for sure.

Thank you.

petri commented 4 years ago

So it seems that a bigger unpack structure is defined than what's passed as byte_arr (or part of byte_arr starting from offset. Really hard to tell why this happens without more information. Could be malformed TNEF, or tnefparse not knowing that valid shorter structure is a possibility here.

Sam-Gracy commented 4 years ago

I am closing this issue, since I am not able to provide the winmail.dat