]> granicus.if.org Git - taglib/commitdiff
Fix off-by-one error in MP4::Tag when looking for free padding to use
authorLukáš Lalinský <lalinsky@gmail.com>
Wed, 29 Apr 2009 15:12:19 +0000 (15:12 +0000)
committerLukáš Lalinský <lalinsky@gmail.com>
Wed, 29 Apr 2009 15:12:19 +0000 (15:12 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@961160 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/mp4/mp4tag.cpp
tests/data/ilst-is-last.m4a [new file with mode: 0644]
tests/test_mp4.cpp

index 47a5b79d4581948fc55bbb289b8e83c6b4b2523b..645d4976545c8be2ea9bf05d6e9d3cc8eaddce6e 100644 (file)
@@ -420,6 +420,8 @@ MP4::Tag::saveExisting(ByteVector &data, AtomList &path)
 
   MP4::Atom *meta = path[path.size() - 2];
   AtomList::Iterator index = meta->children.find(ilst);
+
+  // check if there is an atom before 'ilst', and possibly use it as padding
   if(index != meta->children.begin()) {
     AtomList::Iterator prevIndex = index;
     prevIndex--;
@@ -429,9 +431,10 @@ MP4::Tag::saveExisting(ByteVector &data, AtomList &path)
       length += prev->length;
     }
   }
-  if(index != meta->children.end()) {
-    AtomList::Iterator nextIndex = index;
-    nextIndex++;
+  // check if there is an atom after 'ilst', and possibly use it as padding
+  AtomList::Iterator nextIndex = index;
+  nextIndex++;
+  if(nextIndex != meta->children.end()) {
     MP4::Atom *next = *nextIndex;
     if(next->name == "free") {
       length += next->length;
diff --git a/tests/data/ilst-is-last.m4a b/tests/data/ilst-is-last.m4a
new file mode 100644 (file)
index 0000000..c56c804
Binary files /dev/null and b/tests/data/ilst-is-last.m4a differ
index 2bca203b5538237b9ee5c908082c8e716ddf3f87..04ad729aff600296b5b28c4b82263c6bf11d01e8 100644 (file)
@@ -17,6 +17,7 @@ class TestMP4 : public CppUnit::TestFixture
   CPPUNIT_TEST(testProperties);
   CPPUNIT_TEST(testFreeForm);
   CPPUNIT_TEST(testUpdateStco);
+  CPPUNIT_TEST(testSaveExisingWhenIlstIsLast);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -98,6 +99,25 @@ public:
     deleteFile(filename);
   }
 
+  void testSaveExisingWhenIlstIsLast()
+  {
+    string filename = copyFile("ilst-is-last", ".m4a");
+
+    MP4::File *f = new MP4::File(filename.c_str());
+    CPPUNIT_ASSERT_EQUAL(String("82,164"), f->tag()->itemListMap()["----:com.apple.iTunes:replaygain_track_minmax"].toStringList()[0]);
+    CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist());
+    f->tag()->setComment("foo");
+    f->save();
+    delete f;
+
+    f = new MP4::File(filename.c_str());
+    CPPUNIT_ASSERT_EQUAL(String("82,164"), f->tag()->itemListMap()["----:com.apple.iTunes:replaygain_track_minmax"].toStringList()[0]);
+    CPPUNIT_ASSERT_EQUAL(String("Pearl Jam"), f->tag()->artist());
+    CPPUNIT_ASSERT_EQUAL(String("foo"), f->tag()->comment());
+
+    deleteFile(filename);
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestMP4);