Skip to content

decode_terminated causes an endless loop #373

Open
@snahor

Description

@snahor

decode_terminated seems to be failing with some files causing the endless loop in https://github.com/quodlibet/mutagen/blob/release-1.42.0/mutagen/id3/_specs.py#L507.

It seems to happen with "faulty"(?) audio files. I know close to nothing about mutagen, id3, mp3, etc. But I'd be happy to help fixing it with some guidance.

Test code:

import mutagen, sys, magic

print(magic.from_file(sys.argv[1], mime=True))
print(mutagen.File(sys.argv[1], easy=True))

Output:

application/octet-stream
^CTraceback (most recent call last):
  File "foo.py", line 8, in <module>
    print(mutagen.File(sys.argv[1], easy=True))
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/_util.py", line 148, in wrapper_func
    return func(h, *args, **kwargs)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/_file.py", line 298, in File
    return Kind(fileobj, filename=filething.filename)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/_file.py", line 49, in __init__
    self.load(*args, **kwargs)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/_util.py", line 140, in wrapper
    return func(self, h, *args, **kwargs)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_file.py", line 411, in load
    self.tags = ID3(fileobj, **kwargs)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/easyid3.py", line 170, in __init__
    self.load(filename)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/_util.py", line 169, in wrapper
    return func(*args, **kwargs)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/_util.py", line 140, in wrapper
    return func(self, h, *args, **kwargs)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_file.py", line 173, in load
    remaining_data = self._read(self._header, data)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_tags.py", line 181, in _read
    header, data, header.known_frames)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_tags.py", line 596, in read_frames
    result.append(tag._fromData(id3, flags, framedata))
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_frames.py", line 291, in _fromData
    frame._readData(header, data)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_frames.py", line 179, in _readData
    value, data = reader.read(id3, self, data)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_specs.py", line 510, in read
    value, data = spec.read(header, frame, data)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/id3/_specs.py", line 475, in read
    value, data = decode_terminated(data, enc, strict=False)
  File "/tmp/venv3/lib/python3.6/site-packages/mutagen/_util.py", line 1010, in decode_terminated
    return data[:index].decode(encoding), data[index + 1:]
KeyboardInterrupt

If it helps, this is the output if I use eyeD3:

eyed3.plugins:WARNING: Plugin '('lastfm.py', '/tmp/venv3/lib/python3.6/site-packages/eyed3/plugins')' requires packages that are not installed: No module named 'pylast'
eyed3.id3.frames:WARNING: TextFrame[b'TIT2'] - Unknown encoding value b't'; using latin1
/tmp/Brotherhood_Of_The_Snake.mp3                                                                                                                                                                 [ 14.89 MB ]
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 04:14     MPEG1, Layer III        [ 320 kb/s @ 44100 Hz - Joint stereo ]
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID3 v2.4:
title: therhood Of The Snake
artist:
album: TestamentTALB1Brotherhood Of The SnakeTYER       2016TCON        (12)
track: 1
Comment: [Description: ] [Lang: eng]

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Faulty file: https://drive.google.com/open?id=1mEZSqRbvHiMmAp_TwTEz_mJMbhDpc1KH

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions