dhamaniasad / mutagen

Automatically exported from code.google.com/p/mutagen
GNU General Public License v2.0
2 stars 1 forks source link

APEv2 throws exception when data.items is greater than actual number of tags #145

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have a lot of MPC files that failed to be parsed by mutagen:

from mutagen.apev2 import APEv2
audio = APEv2(<path_to_mpc_file>

I get the following traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/mutagen/apev2.py", line 192, in __init__
    super(APEv2, self).__init__(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/mutagen/__init__.py", line 37, in __init__
    self.load(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/mutagen/apev2.py", line 217, in load
    self.__parse_tag(data.tag, data.items)
  File "/usr/lib/python2.7/site-packages/mutagen/apev2.py", line 240, in __parse_tag
    self[key] = APEValue(value, kind)
  File "/usr/lib/python2.7/site-packages/mutagen/apev2.py", line 270, in __setitem__
    raise KeyError("%r is not a valid APEv2 key" % key)
KeyError: "'\\xd0\\x07' is not a valid APEv2 key"

The reason why this happens for me is that all the MPC files I have have an 
incorrect tag count embedded in APE footer/header eg 18 instead of 17. This 
means that mutagen is trying to parse the footer bytes as an actual tag, hence 
the exception.

I see that there is a _is_valid_ape2_key function which I think could be used 
to check before setting the key during __parse_tag method call.

Of course, the best solution would be for me to write a script to correct the 
misformatted footer/header data, however, other libraries seem to handle such 
scenario - Exaile is the only player that is unable to read the tags due to 
this issue whereas other players (like e.g rhythmbox, foobar2000 etc) handle it 
fine and I'm not the only person affected by this:

https://bugs.launchpad.net/exaile/+bug/521228

Original issue reported on code.google.com by dzr...@gmail.com on 21 Apr 2013 at 3:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Added a simple patch to fix this in a least invasive manner I hope.

Original comment by dzr...@gmail.com on 21 Apr 2013 at 6:01

Attachments:

GoogleCodeExporter commented 9 years ago
Can you provide an example file (mail,dropbox etc..)?

Original comment by reiter.christoph@gmail.com on 21 Apr 2013 at 6:27

GoogleCodeExporter commented 9 years ago
Here you go:
http://maners.no-ip.org/11%20-%20High%20Hopes.mpc

Original comment by dzr...@gmail.com on 21 Apr 2013 at 6:57

GoogleCodeExporter commented 9 years ago
P.S. If you look at this file with hex editor you'll see that the APE tag 
footer at 0xD927DA has value of 0x12 for the number of tags but the actual 
number of tags is 17 (0x11). Not sure what program caused such corruption but I 
have plenty of files like that.

Original comment by dzr...@gmail.com on 21 Apr 2013 at 7:03

GoogleCodeExporter commented 9 years ago
Thanks

Original comment by reiter.christoph@gmail.com on 21 Apr 2013 at 8:20

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 82ba5baa6376.

Original comment by reiter.christoph@gmail.com on 21 Apr 2013 at 10:46