]> granicus.if.org Git - taglib/commitdiff
Fix reading table of contents frames with a lot of children.
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 14 May 2016 00:58:19 +0000 (09:58 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Sat, 14 May 2016 00:58:19 +0000 (09:58 +0900)
taglib/mpeg/id3v2/frames/tableofcontentsframe.cpp
tests/data/toc_many_children.mp3 [new file with mode: 0644]
tests/test_id3v2.cpp

index 507203590822c05ff0684fdafc7f664ed991592b..f797125017f4098c80fb1b6a0290499423fb6136 100644 (file)
@@ -272,9 +272,9 @@ void TableOfContentsFrame::parseFields(const ByteVector &data)
   int pos = 0;
   unsigned int embPos = 0;
   d->elementID = readStringField(data, String::Latin1, &pos).data(String::Latin1);
-  d->isTopLevel = (data.at(pos) & 2) > 0;
-  d->isOrdered = (data.at(pos++) & 1) > 0;
-  unsigned int entryCount = data.at(pos++);
+  d->isTopLevel = (data.at(pos) & 2) != 0;
+  d->isOrdered = (data.at(pos++) & 1) != 0;
+  unsigned int entryCount = static_cast<unsigned char>(data.at(pos++));
   for(unsigned int i = 0; i < entryCount; i++) {
     ByteVector childElementID = readStringField(data, String::Latin1, &pos).data(String::Latin1);
     d->childElements.append(childElementID);
diff --git a/tests/data/toc_many_children.mp3 b/tests/data/toc_many_children.mp3
new file mode 100644 (file)
index 0000000..168c479
Binary files /dev/null and b/tests/data/toc_many_children.mp3 differ
index 93a3d2c24b7539e52a80c2163eca8bdebcaa4ca1..4f58bdd6b7fe215cb28a2c3a8ee67b4474633b73 100644 (file)
@@ -118,6 +118,7 @@ class TestID3v2 : public CppUnit::TestFixture
   CPPUNIT_TEST(testShrinkPadding);
   CPPUNIT_TEST(testEmptyFrame);
   CPPUNIT_TEST(testDuplicateTags);
+  CPPUNIT_TEST(testParseTOCFrameWithManyChildren);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -1217,6 +1218,12 @@ public:
     }
   }
 
+  void testParseTOCFrameWithManyChildren()
+  {
+    MPEG::File f(TEST_FILE_PATH_C("toc_many_children.mp3"));
+    CPPUNIT_ASSERT(f.isValid());
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v2);