Protect against incorrect ID3v2 version parameter

This commit is contained in:
Lukáš Lalinský 2011-04-05 15:36:23 +02:00
parent aa57db3a39
commit 3715b96477
2 changed files with 25 additions and 0 deletions

View File

@ -438,6 +438,11 @@ ByteVector ID3v2::Tag::render(int version) const
ByteVector tagData;
if(version != 3 && version != 4) {
debug("Unknown ID3v2 version, using ID3v2.4");
version = 4;
}
// TODO: Render the extended header.
// Loop through the frames rendering them and adding them to the tagData.

View File

@ -13,6 +13,7 @@ class TestMPEG : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(TestMPEG);
CPPUNIT_TEST(testVersion2DurationWithXingHeader);
CPPUNIT_TEST(testSaveID3v24);
CPPUNIT_TEST(testSaveID3v24WrongParam);
CPPUNIT_TEST(testSaveID3v23);
CPPUNIT_TEST_SUITE_END();
@ -36,6 +37,24 @@ public:
f.save(MPEG::File::AllTags, true, 4);
MPEG::File f2(newname.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f2.ID3v2Tag()->header()->majorVersion());
CPPUNIT_ASSERT_EQUAL(String("Artist A"), f2.tag()->artist());
CPPUNIT_ASSERT_EQUAL(xxx, f2.tag()->title());
}
void testSaveID3v24WrongParam()
{
ScopedFileCopy copy("xing", ".mp3");
string newname = copy.fileName();
String xxx = ByteVector(254, 'X');
MPEG::File f(newname.c_str());
f.tag()->setTitle(xxx);
f.tag()->setArtist("Artist A");
f.save(MPEG::File::AllTags, true, 8);
MPEG::File f2(newname.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(4), f2.ID3v2Tag()->header()->majorVersion());
CPPUNIT_ASSERT_EQUAL(String("Artist A"), f2.tag()->artist());
CPPUNIT_ASSERT_EQUAL(xxx, f2.tag()->title());
}
@ -52,6 +71,7 @@ public:
f.save(MPEG::File::AllTags, true, 3);
MPEG::File f2(newname.c_str());
CPPUNIT_ASSERT_EQUAL(TagLib::uint(3), f2.ID3v2Tag()->header()->majorVersion());
CPPUNIT_ASSERT_EQUAL(String("Artist A"), f2.tag()->artist());
CPPUNIT_ASSERT_EQUAL(xxx, f2.tag()->title());
}