Skip to content

Commit eb237c1

Browse files
committed
PICARD-2774: Do not fail loading files with invalid ID3 image types
1 parent 892693b commit eb237c1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

picard/coverart/image.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,17 @@ def __init__(self, url=None, types=None, comment='', data=None, support_types=No
170170
self.can_be_saved_to_tags = True
171171
self.can_be_saved_to_disk = True
172172
self.can_be_saved_to_metadata = True
173-
self.id3_type = id3_type
174173
if support_types is not None:
175174
self.support_types = support_types
176175
if support_multi_types is not None:
177176
self.support_multi_types = support_multi_types
178177
if data is not None:
179178
self.set_data(data)
179+
try:
180+
self.id3_type = id3_type
181+
except ValueError:
182+
log.warning("Invalid ID3 image type %r in %r", type, self)
183+
self.id3_type = Id3ImageType.OTHER
180184

181185
@property
182186
def source(self):

test/test_coverart_image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ def test_id3_type_value_error(self):
148148
with self.assertRaises(ValueError):
149149
image.id3_type = invalid_value
150150

151+
def test_init_invalid_id3_type(self):
152+
image = CoverArtImage(id3_type=255)
153+
self.assertEqual(image.id3_type, Id3ImageType.OTHER)
154+
151155
def test_compare_without_type(self):
152156
image1 = create_image(b'a', types=["front"])
153157
image2 = create_image(b'a', types=["back"])

0 commit comments

Comments
 (0)