- Fixed crash in AttachedPictureFrame and GeneralEncapsulatedObjectFrame

caused by using uninitialized pointer. (BUG:151078)
- Make Frame::readStringField to actually read the string field.
- Fixed parsing of APIC frames -- there is one-byte type between mime type
  and description. The code worked only thanks to the previous bug.


git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@735035 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Lukáš Lalinský
2007-11-10 18:03:25 +00:00
parent db0be6b8c6
commit 673b77c3ac
4 changed files with 67 additions and 5 deletions

View File

@ -54,8 +54,8 @@ AttachedPictureFrame::AttachedPictureFrame() : Frame("APIC")
AttachedPictureFrame::AttachedPictureFrame(const ByteVector &data) : Frame(data)
{
setData(data);
d = new AttachedPictureFramePrivate;
setData(data);
}
AttachedPictureFrame::~AttachedPictureFrame()
@ -132,9 +132,10 @@ void AttachedPictureFrame::parseFields(const ByteVector &data)
d->textEncoding = String::Type(data[0]);
int pos = 1;
int pos = 1;
d->mimeType = readStringField(data, String::Latin1, &pos);
d->mimeType = readStringField(data, String::Latin1, &pos);
d->type = (TagLib::ID3v2::AttachedPictureFrame::Type)data[pos++];
d->description = readStringField(data, d->textEncoding, &pos);
d->data = data.mid(pos);

View File

@ -55,8 +55,8 @@ GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame() : Frame("GEOB")
GeneralEncapsulatedObjectFrame::GeneralEncapsulatedObjectFrame(const ByteVector &data) : Frame(data)
{
setData(data);
d = new GeneralEncapsulatedObjectFramePrivate;
setData(data);
}
GeneralEncapsulatedObjectFrame::~GeneralEncapsulatedObjectFrame()

View File

@ -202,9 +202,11 @@ String Frame::readStringField(const ByteVector &data, String::Type encoding, int
if(end < *position)
return String::null;
String str = String(data.mid(*position, end - *position), encoding);
*position = end + delimiter.size();
return String(data.mid(*position, end - *position), encoding);
return str;
}

View File

@ -3,17 +3,35 @@
#include <stdio.h>
#include <id3v2tag.h>
#include <mpegfile.h>
#include <id3v2frame.h>
#include <textidentificationframe.h>
#include <attachedpictureframe.h>
#include <generalencapsulatedobjectframe.h>
using namespace std;
using namespace TagLib;
class PublicFrame : public ID3v2::Frame
{
public:
PublicFrame() : ID3v2::Frame(ByteVector("XXXX\0\0\0\0\0\0", 10)) {}
String readStringField(const ByteVector &data, String::Type encoding,
int *positon = 0)
{ return ID3v2::Frame::readStringField(data, encoding, positon); }
virtual String toString() const { return String::null; }
virtual void parseFields(const ByteVector &) {}
virtual ByteVector renderFields() const { return ByteVector::null; }
};
class TestID3v2 : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestID3v2);
CPPUNIT_TEST(testUnsynchDecode);
CPPUNIT_TEST(testUTF16BEDelimiter);
CPPUNIT_TEST(testUTF16Delimiter);
CPPUNIT_TEST(testReadStringField);
CPPUNIT_TEST(testParseAPIC);
CPPUNIT_TEST(testParseGEOB);
CPPUNIT_TEST(testBrokenFrame1);
//CPPUNIT_TEST(testItunes24FrameSize);
CPPUNIT_TEST_SUITE_END();
@ -54,6 +72,47 @@ public:
CPPUNIT_ASSERT(!f.ID3v2Tag()->frameListMap().contains("TENC"));
}
void testReadStringField()
{
PublicFrame f;
ByteVector data("abc\0", 4);
String str = f.readStringField(data, String::Latin1);
CPPUNIT_ASSERT_EQUAL(String("abc"), str);
}
// http://bugs.kde.org/show_bug.cgi?id=151078
void testParseAPIC()
{
ID3v2::AttachedPictureFrame f(ByteVector("APIC"
"\x00\x00\x00\x07"
"\x00\x00"
"\x00"
"m\x00"
"\x01"
"d\x00"
"\x00", 17));
CPPUNIT_ASSERT_EQUAL(String("m"), f.mimeType());
CPPUNIT_ASSERT_EQUAL(ID3v2::AttachedPictureFrame::FileIcon, f.type());
CPPUNIT_ASSERT_EQUAL(String("d"), f.description());
}
// http://bugs.kde.org/show_bug.cgi?id=151078
void testParseGEOB()
{
ID3v2::GeneralEncapsulatedObjectFrame f(ByteVector("GEOB"
"\x00\x00\x00\x08"
"\x00\x00"
"\x00"
"m\x00"
"f\x00"
"d\x00"
"\x00", 18));
CPPUNIT_ASSERT_EQUAL(String("m"), f.mimeType());
CPPUNIT_ASSERT_EQUAL(String("f"), f.fileName());
CPPUNIT_ASSERT_EQUAL(String("d"), f.description());
}
/*void testItunes24FrameSize()
{
MPEG::File f("data/005411.id3", false);