Fix segfaults when calling File::properties() after strip().

Backport TagUnion::properties() and TagUnion::removeUnsupportedProperties() from taglib2.
This commit is contained in:
Tsuda Kageyu
2015-08-03 23:41:26 +09:00
parent 1bb06b1f7a
commit c5cf9b93bc
15 changed files with 253 additions and 92 deletions

View File

@ -1,8 +1,10 @@
#include <string>
#include <stdio.h>
#include <tag.h>
#include <apetag.h>
#include <id3v1tag.h>
#include <tstringlist.h>
#include <tbytevectorlist.h>
#include <tpropertymap.h>
#include <apefile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -20,6 +22,7 @@ class TestAPE : public CppUnit::TestFixture
CPPUNIT_TEST(testProperties390);
CPPUNIT_TEST(testFuzzedFile1);
CPPUNIT_TEST(testFuzzedFile2);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST_SUITE_END();
public:
@ -111,6 +114,26 @@ public:
CPPUNIT_ASSERT(f.isValid());
}
void testStripAndProperties()
{
ScopedFileCopy copy("mac-399", ".ape");
{
APE::File f(copy.fileName().c_str());
f.APETag(true)->setTitle("APE");
f.ID3v1Tag(true)->setTitle("ID3v1");
f.save();
}
{
APE::File f(copy.fileName().c_str());
CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
f.strip(APE::File::APE);
CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
f.strip(APE::File::ID3v1);
CPPUNIT_ASSERT(f.properties().isEmpty());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestAPE);

View File

@ -1,8 +1,10 @@
#include <string>
#include <stdio.h>
#include <tag.h>
#include <apetag.h>
#include <id3v1tag.h>
#include <tstringlist.h>
#include <tbytevectorlist.h>
#include <tpropertymap.h>
#include <mpcfile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -21,6 +23,7 @@ class TestMPC : public CppUnit::TestFixture
CPPUNIT_TEST(testFuzzedFile2);
CPPUNIT_TEST(testFuzzedFile3);
CPPUNIT_TEST(testFuzzedFile4);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST_SUITE_END();
public:
@ -109,6 +112,26 @@ public:
CPPUNIT_ASSERT(f.isValid());
}
void testStripAndProperties()
{
ScopedFileCopy copy("click", ".mpc");
{
MPC::File f(copy.fileName().c_str());
f.APETag(true)->setTitle("APE");
f.ID3v1Tag(true)->setTitle("ID3v1");
f.save();
}
{
MPC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
f.strip(MPC::File::APE);
CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
f.strip(MPC::File::ID3v1);
CPPUNIT_ASSERT(f.properties().isEmpty());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMPC);

View File

@ -1,8 +1,11 @@
#include <string>
#include <stdio.h>
#include <tstring.h>
#include <tpropertymap.h>
#include <mpegfile.h>
#include <id3v2tag.h>
#include <id3v1tag.h>
#include <apetag.h>
#include <mpegproperties.h>
#include <xingheader.h>
#include <mpegheader.h>
@ -26,6 +29,7 @@ class TestMPEG : public CppUnit::TestFixture
CPPUNIT_TEST(testDuplicateID3v2);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST(testFrameOffset);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST_SUITE_END();
public:
@ -212,6 +216,29 @@ public:
}
}
void testStripAndProperties()
{
ScopedFileCopy copy("xing", ".mp3");
{
MPEG::File f(copy.fileName().c_str());
f.ID3v2Tag(true)->setTitle("ID3v2");
f.APETag(true)->setTitle("APE");
f.ID3v1Tag(true)->setTitle("ID3v1");
f.save();
}
{
MPEG::File f(copy.fileName().c_str());
CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front());
f.strip(MPEG::File::ID3v2);
CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
f.strip(MPEG::File::APE);
CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
f.strip(MPEG::File::ID3v1);
CPPUNIT_ASSERT(f.properties().isEmpty());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestMPEG);

View File

@ -1,5 +1,8 @@
#include <string>
#include <stdio.h>
#include <id3v1tag.h>
#include <id3v2tag.h>
#include <tpropertymap.h>
#include <trueaudiofile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -12,6 +15,7 @@ class TestTrueAudio : public CppUnit::TestFixture
CPPUNIT_TEST_SUITE(TestTrueAudio);
CPPUNIT_TEST(testReadPropertiesWithoutID3v2);
CPPUNIT_TEST(testReadPropertiesWithTags);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST_SUITE_END();
public:
@ -46,6 +50,26 @@ public:
CPPUNIT_ASSERT_EQUAL(1, f.audioProperties()->ttaVersion());
}
void testStripAndProperties()
{
ScopedFileCopy copy("empty", ".tta");
{
TrueAudio::File f(copy.fileName().c_str());
f.ID3v2Tag(true)->setTitle("ID3v2");
f.ID3v1Tag(true)->setTitle("ID3v1");
f.save();
}
{
TrueAudio::File f(copy.fileName().c_str());
CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front());
f.strip(TrueAudio::File::ID3v2);
CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
f.strip(TrueAudio::File::ID3v1);
CPPUNIT_ASSERT(f.properties().isEmpty());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestTrueAudio);

View File

@ -1,9 +1,9 @@
#include <string>
#include <stdio.h>
#include <tag.h>
#include <id3v2tag.h>
#include <infotag.h>
#include <tbytevectorlist.h>
#include <tpropertymap.h>
#include <wavfile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -24,6 +24,7 @@ class TestWAV : public CppUnit::TestFixture
CPPUNIT_TEST(testDuplicateTags);
CPPUNIT_TEST(testFuzzedFile1);
CPPUNIT_TEST(testFuzzedFile2);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST_SUITE_END();
public:
@ -211,6 +212,26 @@ public:
CPPUNIT_ASSERT(f2.isValid());
}
void testStripAndProperties()
{
ScopedFileCopy copy("empty", ".wav");
{
RIFF::WAV::File f(copy.fileName().c_str());
f.ID3v2Tag()->setTitle("ID3v2");
f.InfoTag()->setTitle("INFO");
f.save();
}
{
RIFF::WAV::File f(copy.fileName().c_str());
CPPUNIT_ASSERT_EQUAL(String("ID3v2"), f.properties()["TITLE"].front());
f.strip(RIFF::WAV::File::ID3v2);
CPPUNIT_ASSERT_EQUAL(String("INFO"), f.properties()["TITLE"].front());
f.strip(RIFF::WAV::File::Info);
CPPUNIT_ASSERT(f.properties().isEmpty());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV);

View File

@ -1,7 +1,9 @@
#include <string>
#include <stdio.h>
#include <tag.h>
#include <apetag.h>
#include <id3v1tag.h>
#include <tbytevectorlist.h>
#include <tpropertymap.h>
#include <wavpackfile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -16,6 +18,7 @@ class TestWavPack : public CppUnit::TestFixture
CPPUNIT_TEST(testMultiChannelProperties);
CPPUNIT_TEST(testTaggedProperties);
CPPUNIT_TEST(testFuzzedFile);
CPPUNIT_TEST(testStripAndProperties);
CPPUNIT_TEST_SUITE_END();
public:
@ -73,6 +76,27 @@ public:
WavPack::File f(TEST_FILE_PATH_C("infloop.wv"));
CPPUNIT_ASSERT(f.isValid());
}
void testStripAndProperties()
{
ScopedFileCopy copy("click", ".wv");
{
WavPack::File f(copy.fileName().c_str());
f.APETag(true)->setTitle("APE");
f.ID3v1Tag(true)->setTitle("ID3v1");
f.save();
}
{
WavPack::File f(copy.fileName().c_str());
CPPUNIT_ASSERT_EQUAL(String("APE"), f.properties()["TITLE"].front());
f.strip(WavPack::File::APE);
CPPUNIT_ASSERT_EQUAL(String("ID3v1"), f.properties()["TITLE"].front());
f.strip(WavPack::File::ID3v1);
CPPUNIT_ASSERT(f.properties().isEmpty());
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestWavPack);