Skip to content

Commit

Permalink
ID3: Consider size of extended header when reading ID3 data
Browse files Browse the repository at this point in the history
Fixes #630
  • Loading branch information
phw committed Oct 1, 2023
1 parent e492ebe commit cc18b4b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mutagen/id3/_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ class XMYF(Frame): ...
if known_frames is not None:
self._header._known_frames = known_frames

data = read_full(fileobj, self.size - 10)
size = self.size - 10
if self.f_extended:
size -= 4 + len(self._header._extdata)
data = read_full(fileobj, size)
remaining_data = self._read(self._header, data)
self._padding = len(remaining_data)

Expand Down
Binary file added tests/data/id3v24_extended_header.id3
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/test_id3.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TID3Read(TestCase):
silence = os.path.join(DATA_DIR, 'silence-44-s.mp3')
silence_v1 = os.path.join(DATA_DIR, 'silence-44-s-v1.mp3')
unsynch = os.path.join(DATA_DIR, 'id3v23_unsynch.id3')
extended_header = os.path.join(DATA_DIR, 'id3v24_extended_header.id3')
v22 = os.path.join(DATA_DIR, "id3v22-test.mp3")
bad_tyer = os.path.join(DATA_DIR, 'bad-TYER-frame.mp3')
v1v2_combined = os.path.join(DATA_DIR, "id3v1v2-combined.mp3")
Expand Down Expand Up @@ -232,6 +233,10 @@ def test_load_v23_unsynch(self):
id3 = ID3(self.unsynch)
self.assertEquals(id3["TPE1"], ["Nina Simone"])

def test_v24_extended_header(self):
id3 = ID3(self.extended_header)
self.assertEquals(id3["TIT2"], ["One Second of Silence"])

def test_bad_extended_header_flags(self):
# Files with bad extended header flags failed to read tags.
# Ensure the extended header is turned off, and the frames are
Expand Down

0 comments on commit cc18b4b

Please sign in to comment.