Skip to content

Commit

Permalink
Merge pull request #1260 from kiefermat/index_error_on_unknown_cover_…
Browse files Browse the repository at this point in the history
…type

Fixed IndexError on reading embedded cover art with invalid cover type
  • Loading branch information
sampsyo committed Jan 23, 2015
2 parents b30c697 + b168987 commit 3336f56
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion beets/mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ def __init__(self, data, desc=None, type=None):
self.data = data
self.desc = desc
if isinstance(type, int):
type = list(ImageType)[type]
try:
type = list(ImageType)[type]
except IndexError:
log.warn("ignoring unknown image type index {}", type)
type = ImageType.other
self.type = type

@property
Expand Down
Binary file added test/rsrc/image_unknown_type.mp3
Binary file not shown.
4 changes: 4 additions & 0 deletions test/test_mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ class MP3Test(ReadWriteTestBase, PartialTestMixin,
'channels': 1,
}

def test_unknown_apic_type(self):
mediafile = self._mediafile_fixture('image_unknown_type')
self.assertEqual(mediafile.images[0].type, ImageType.other)


class MP4Test(ReadWriteTestBase, PartialTestMixin,
ImageStructureTestMixin, unittest.TestCase):
Expand Down

0 comments on commit 3336f56

Please sign in to comment.