File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -201,12 +201,19 @@ void Header::parse(const ByteVector &data)
201201 if (std::any_of (sizeData.cbegin (), sizeData.cend (),
202202 [](unsigned char size) { return size >= 128 ; })) {
203203 d->tagSize = 0 ;
204- debug (" TagLib::ID3v2::Header::parse() - One of the size bytes in the id3v2 header was greater than the allowed 128." );
204+ debug (" TagLib::ID3v2::Header::parse() - One of the size bytes in the ID3v2 header was greater than the allowed 128." );
205205 return ;
206206 }
207207
208208 // The first three bytes, data[0..2], are the File Identifier, "ID3". (structure 3.1 "file identifier")
209209
210+ // 3.1 states: "Version or revision will never be $FF."
211+ if (static_cast <unsigned char >(data[3 ]) == 0xFF || static_cast <unsigned char >(data[4 ]) == 0xFF ) {
212+ d->tagSize = 0 ;
213+ debug (" TagLib::ID3v2::Header::parse() - The version or revision in the ID3v2 header was 0xFF." );
214+ return ;
215+ }
216+
210217 // Read the version number from the fourth and fifth bytes.
211218 d->majorVersion = data[3 ]; // (structure 3.1 "major version")
212219 d->revisionNumber = data[4 ]; // (structure 3.1 "revision number")
Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ class TestID3v2 : public CppUnit::TestFixture
139139 CPPUNIT_TEST (testEmptyFrame);
140140 CPPUNIT_TEST (testDuplicateTags);
141141 CPPUNIT_TEST (testParseTOCFrameWithManyChildren);
142+ CPPUNIT_TEST (testInvalidID3v2Version);
142143 CPPUNIT_TEST_SUITE_END ();
143144
144145public:
@@ -1739,6 +1740,21 @@ class TestID3v2 : public CppUnit::TestFixture
17391740 CPPUNIT_ASSERT (tocFrame->embeddedFrameList ().isEmpty ());
17401741 }
17411742
1743+ void testInvalidID3v2Version ()
1744+ {
1745+ ID3v2::Header invalidVersionHeader (ByteVector (" ID3"
1746+ " \xFF\x00 "
1747+ " \x05 "
1748+ " \x14\x4F\x00\x32 " , 10 ));
1749+ CPPUNIT_ASSERT_EQUAL (invalidVersionHeader.tagSize (), 0U );
1750+
1751+ ID3v2::Header invalidRevisionHeader (ByteVector (" ID3"
1752+ " \x04\xFF "
1753+ " \x05 "
1754+ " \x14\x4F\x00\x32 " , 10 ));
1755+ CPPUNIT_ASSERT_EQUAL (invalidRevisionHeader.tagSize (), 0U );
1756+ }
1757+
17421758};
17431759
17441760CPPUNIT_TEST_SUITE_REGISTRATION (TestID3v2);
You can’t perform that action at this time.
0 commit comments