tinytag
tinytag copied to clipboard
[BUG] struct.error: unpack requires a buffer of 4 bytes
Describe the bug
When I trying to get file duration:
TinyTag.get(filename).duration
and for some files I have exception:
return TinyTag.get(filename).duration
File "/opt/virtualenvs/lib/python3.6/site-packages/tinytag/tinytag.py", line 194, in get
tag.load(tags=tags, duration=duration, image=image)
File "/opt/virtualenvs/lib/python3.6/site-packages/tinytag/tinytag.py", line 212, in load
self._determine_duration(self._filehandler)
File "/opt/virtualenvs/lib/python3.6/site-packages/tinytag/tinytag.py", line 655, in _determine_duration
xframes, byte_count, toc, vbr_scale = ID3._parse_xing_header(fh)
File "/opt/virtualenvs/lib/python3.6/site-packages/tinytag/tinytag.py", line 604, in _parse_xing_header
vbr_scale = struct.unpack('>i', fh.read(4))[0]
struct.error: unpack requires a buffer of 4 bytes
Expected behavior I think that the file is damaged but tinytag should return 0 for duration, not raising strange exception. Or raising own exception.
Sample File I can't upload it :(
I could look into the issue. Can you attach the file in a zip archive, or send it to my email (on my profile)?
@mathiascode I sent file to you (mail).
Thanks, I found the issue: https://github.com/devsnd/tinytag/blob/1fb8d78551d735597d042e2c5993173bd1aa36a5/tinytag/tinytag.py#L600-L601
TOC is 100 bytes, but we're currently reading 400 bytes. Seems like nobody noticed this error, since the values for TOC and VBR SCALE aren't used anywhere in tinytag.
Thanks @mathiascode !
@mathiascode I have one more question, do you know, when PR will be merged?
Whenever @devsnd has time to merge it, but I don't know when that is.
Just merged it, will release a new version with the fix soon.
@devsnd maybe is it good time to release new version?