diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index c7eb6d61..b13dcc39 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -352,6 +352,11 @@ ByteVector ID3v2::Tag::render() const // Loop through the frames rendering them and adding them to the tagData. for(FrameList::Iterator it = d->frameList.begin(); it != d->frameList.end(); it++) { + if ((*it)->header()->frameID().size() != 4) { + debug("A frame of unsupported or unknown type \'" + + String((*it)->header()->frameID()) + "\' has been discarded"); + continue; + } if(!(*it)->header()->tagAlterPreservation()) tagData.append((*it)->render()); } diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index 5aeaa861..0a105069 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -39,6 +39,7 @@ class TestID3v2 : public CppUnit::TestFixture CPPUNIT_TEST(testParseAPIC); CPPUNIT_TEST(testParseAPIC_UTF16_BOM); CPPUNIT_TEST(testParseAPICv22); + CPPUNIT_TEST(testDontRender22); CPPUNIT_TEST(testParseGEOB); CPPUNIT_TEST(testPOPMtoString); CPPUNIT_TEST(testParsePOPM); @@ -152,6 +153,26 @@ public: CPPUNIT_ASSERT_EQUAL(String("d"), frame->description()); } + void testDontRender22() + { + ID3v2::FrameFactory *factory = ID3v2::FrameFactory::instance(); + ByteVector data = ByteVector("FOO" + "\x00\x00\x08" + "\x00" + "JPG" + "\x01" + "d\x00" + "\x00", 18); + ID3v2::AttachedPictureFrame *frame = + static_cast(factory->createFrame(data, TagLib::uint(2))); + + CPPUNIT_ASSERT(frame); + + ID3v2::Tag tag; + tag.addFrame(frame); + CPPUNIT_ASSERT_EQUAL(TagLib::uint(1034), tag.render().size()); + } + // http://bugs.kde.org/show_bug.cgi?id=151078 void testParseGEOB() {