iluvcapra / wavinfo

Probe WAVE Files for all metadata
https://wavinfo.readthedocs.io/
MIT License
36 stars 7 forks source link

struct.error: unpack requires a buffer of 4 bytes #4

Closed 2mmi closed 4 years ago

2mmi commented 5 years ago

Hi.

Maybe this is a bug ? I have some files that throw this error.

Traceback (most recent call last): File "C:/Users/Tommi/PycharmProjects/netmix/FileScanner/filescanner.py", line 19, in info = WavInfoReader("lyde\DRCD-04_02_01.wav", bext_encoding="latin1") File "C:\Python37\lib\site-packages\wavinfo\wave_reader.py", line 50, in init chunks = parse_chunk(f) File "C:\Python37\lib\site-packages\wavinfo\riff_parser.py", line 63, in parse_chunk return parse_list_chunk(stream=stream, length=size, rf64_context=rf64_context) File "C:\Python37\lib\site-packages\wavinfo\riff_parser.py", line 35, in parse_list_chunk child_chunk = parse_chunk(stream, rf64_context= rf64_context) File "C:\Python37\lib\site-packages\wavinfo\riff_parser.py", line 49, in parse_chunk size = struct.unpack('<I',sizeb)[0] struct.error: unpack requires a buffer of 4 bytes

Right now i did a ugly hack in riff_parser.py at line 49 :) size = struct.unpack('<I',sizeb)[0] if sizeb else 0

Here is the wav file zippet (to big to post on github): https://drive.google.com/file/d/13GCkLJHvux7LBG0Z_fk_4FRcbRgm_LgC/view?usp=sharing

Thanks, Tommi

iluvcapra commented 4 years ago

Hey @2mmi

This file you've provided I think seems to be technically, formally malformed.

The top-level RIFF chunk is asserted to be 65,086,586 bytes long, and this is correct, the file ends exactly that many bytes later, at offset 65,086,594. However, the last nmix/NetMix metadata chunk is asserted to be 1204 bytes, at offset 65,086,586, but its seems to actually be 1212 bytes long. So the parser is expecting another chunk, because the NetMix chunk isn't consuming the whole remainder of the RIFF container.

I'm not sure if this is a NetMix bug or something else. What I've done is instead of your or I'm going to put a try block before the size is parsed, and if the file runs out before the whole chunk header can be read, the code will throw WavInfoEOFError which is a subclass of EOFError. I'll post this in a little bit

iluvcapra commented 4 years ago

This file has some other oddities, the bext chunk seems to be hella broken, the fields aren't formatted properly. What program created this?

2mmi commented 4 years ago

Thank you so much !! I will play around with it on Monday !

Sadly, i don´t know what program encoded the wav file (probably happened MANY years ago), its a part of a bigger sound efx library. But maybe it was the original Netmix: http://www.creativenetworkdesign.com/By-Solution/Sound-FX-Library-Management.html

Netmix in this (Python) context is my own Python web based clone

Keep up your good work !

Best regards Tommi

iluvcapra commented 4 years ago

Okay I get it. This version of the code (5c90d5ff) will succeed in reading your files without throwing an exception, because I've tweaked it to silently dump out if there's extra data in the chunk but not enough to form a new chunk. I'll close this ticket now.