Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lazka opened this issue Jul 4, 2014 · 6 comments
Closed
Labels

Comments

@lazka
Copy link
Member

@lazka lazka commented Jul 4, 2014

Originally reported by: Christoph Reiter (Bitbucket: lazka, GitHub: lazka)


From dzr...@gmail.com on April 21, 2013 05:37:29

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("&#37;r is not a valid APEv2 key" &#37; 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: http://code.google.com/p/mutagen/issues/detail?id=145


@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From reiter.christoph@gmail.com on April 20, 2013 23:27:00

Can you provide an example file (mail,dropbox etc..)?

Status: Accepted

@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From dzr...@gmail.com on April 20, 2013 23:01:11

Added a simple patch to fix this in a least invasive manner I hope.

Attachment: mutagen-apev2.patch

@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From dzr...@gmail.com on April 20, 2013 23:57:03

Here you go: http://maners.no-ip.org/11%20-%20High%20Hopes.mpc
@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From reiter.christoph@gmail.com on April 21, 2013 01:20:44

Thanks
@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From dzr...@gmail.com on April 21, 2013 00:03:00

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.
@lazka

This comment has been minimized.

Copy link
Member Author

@lazka lazka commented Jul 4, 2014

Original comment by Christoph Reiter (Bitbucket: lazka, GitHub: lazka):


From reiter.christoph@gmail.com on April 21, 2013 03:46:15

This issue was closed by revision 82ba5baa6376 .

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.