]> granicus.if.org Git - taglib/commitdiff
Don't underflow if there are no embedded frames
authorScott Wheeler <scott@directededge.com>
Mon, 18 May 2015 15:11:06 +0000 (17:11 +0200)
committerScott Wheeler <scott@directededge.com>
Mon, 18 May 2015 15:11:18 +0000 (17:11 +0200)
Closes #513

taglib/mpeg/id3v2/frames/chapterframe.cpp
tests/test_id3v2.cpp

index ea02f529ce476f657c074140ecfc9b1f24119480..99572888f0670d1c515d2a23b7abe0eda33fdb40 100644 (file)
@@ -239,6 +239,11 @@ void ChapterFrame::parseFields(const ByteVector &data)
   pos += 4;
   size -= pos;
 
+  // Embedded frames are optional
+
+  if(size < header()->size())
+    return;
+
   while((uint)embPos < size - header()->size()) {
     Frame *frame = FrameFactory::instance()->createFrame(data.mid(pos + embPos), d->tagHeader);
 
index 242c6da4b3189d2dad47c97f45fa8c3c55fa6be1..3a18939384fdc2b2a96ab3427055d1ea90c5aea9 100644 (file)
@@ -907,17 +907,25 @@ public:
                  "\x00"                     // TIT2 frame text encoding
                  "CH1", 14);                // Chapter title
 
-    ID3v2::ChapterFrame f(&header, chapterData + embeddedFrameData);
-
-    CPPUNIT_ASSERT_EQUAL(ByteVector("\x43\x00", 2),
-                         f.elementID());
-    CPPUNIT_ASSERT((uint)0x03 == f.startTime());
-    CPPUNIT_ASSERT((uint)0x05 == f.endTime());
-    CPPUNIT_ASSERT((uint)0x02 == f.startOffset());
-    CPPUNIT_ASSERT((uint)0x03 == f.endOffset());
-    CPPUNIT_ASSERT((uint)0x01 == f.embeddedFrameList().size());
-    CPPUNIT_ASSERT(f.embeddedFrameList("TIT2").size() == 1);
-    CPPUNIT_ASSERT(f.embeddedFrameList("TIT2")[0]->toString() == "CH1");
+    ID3v2::ChapterFrame f1(&header, chapterData);
+
+    CPPUNIT_ASSERT_EQUAL(ByteVector("\x43\x00", 2), f1.elementID());
+    CPPUNIT_ASSERT((uint)0x03 == f1.startTime());
+    CPPUNIT_ASSERT((uint)0x05 == f1.endTime());
+    CPPUNIT_ASSERT((uint)0x02 == f1.startOffset());
+    CPPUNIT_ASSERT((uint)0x03 == f1.endOffset());
+    CPPUNIT_ASSERT((uint)0x00 == f1.embeddedFrameList().size());
+
+    ID3v2::ChapterFrame f2(&header, chapterData + embeddedFrameData);
+
+    CPPUNIT_ASSERT_EQUAL(ByteVector("\x43\x00", 2), f2.elementID());
+    CPPUNIT_ASSERT((uint)0x03 == f2.startTime());
+    CPPUNIT_ASSERT((uint)0x05 == f2.endTime());
+    CPPUNIT_ASSERT((uint)0x02 == f2.startOffset());
+    CPPUNIT_ASSERT((uint)0x03 == f2.endOffset());
+    CPPUNIT_ASSERT((uint)0x01 == f2.embeddedFrameList().size());
+    CPPUNIT_ASSERT(f2.embeddedFrameList("TIT2").size() == 1);
+    CPPUNIT_ASSERT(f2.embeddedFrameList("TIT2")[0]->toString() == "CH1");
   }
 
   void testRenderChapterFrame()