Skip to content

Commit

Permalink
PICARD-2774: Do not fail loading files with invalid ID3 image types
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Oct 10, 2023
1 parent 892693b commit eb237c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion picard/coverart/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,17 @@ def __init__(self, url=None, types=None, comment='', data=None, support_types=No
self.can_be_saved_to_tags = True
self.can_be_saved_to_disk = True
self.can_be_saved_to_metadata = True
self.id3_type = id3_type
if support_types is not None:
self.support_types = support_types
if support_multi_types is not None:
self.support_multi_types = support_multi_types
if data is not None:
self.set_data(data)
try:
self.id3_type = id3_type
except ValueError:
log.warning("Invalid ID3 image type %r in %r", type, self)
self.id3_type = Id3ImageType.OTHER

@property
def source(self):
Expand Down
4 changes: 4 additions & 0 deletions test/test_coverart_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def test_id3_type_value_error(self):
with self.assertRaises(ValueError):
image.id3_type = invalid_value

def test_init_invalid_id3_type(self):
image = CoverArtImage(id3_type=255)
self.assertEqual(image.id3_type, Id3ImageType.OTHER)

def test_compare_without_type(self):
image1 = create_image(b'a', types=["front"])
image2 = create_image(b'a', types=["back"])
Expand Down

0 comments on commit eb237c1

Please sign in to comment.