tinytag icon indicating copy to clipboard operation
tinytag copied to clipboard

[BUG] struct.error: unpack requires a buffer of 4 bytes

Open mmazurekdev opened this issue 3 years ago • 6 comments

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 :(

mmazurekdev avatar Jul 18 '22 13:07 mmazurekdev

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 avatar Jul 18 '22 16:07 mathiascode

@mathiascode I sent file to you (mail).

mmazurekdev avatar Jul 19 '22 07:07 mmazurekdev

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.

mathiascode avatar Jul 19 '22 09:07 mathiascode

Thanks @mathiascode !

mmazurekdev avatar Jul 19 '22 12:07 mmazurekdev

@mathiascode I have one more question, do you know, when PR will be merged?

mmazurekdev avatar Jul 21 '22 07:07 mmazurekdev

Whenever @devsnd has time to merge it, but I don't know when that is.

mathiascode avatar Jul 21 '22 10:07 mathiascode

Just merged it, will release a new version with the fix soon.

devsnd avatar Aug 13 '22 15:08 devsnd

@devsnd maybe is it good time to release new version?

mmazurekdev avatar Dec 12 '22 12:12 mmazurekdev