From 2462905fe0cdbb7a37ca66b42a7176b13bbbb09c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Sat, 10 Nov 2007 22:20:33 +0000 Subject: [PATCH] Fix ID3v2::UniqueFileIdentifier frame parsing. According to the spec, the identifier contains arbitrary binary data (which includes \0). That means splitting it on \0 and checking if we have only two parts is wrong, because it rejects valid frames. git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@735109 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- .../frames/uniquefileidentifierframe.cpp | 12 ++++--- tests/test_id3v2.cpp | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp b/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp index 5066e37e..f9ba0368 100644 --- a/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp +++ b/taglib/mpeg/id3v2/frames/uniquefileidentifierframe.cpp @@ -24,6 +24,7 @@ ***************************************************************************/ #include +#include #include "uniquefileidentifierframe.h" @@ -88,13 +89,14 @@ String UniqueFileIdentifierFrame::toString() const void UniqueFileIdentifierFrame::parseFields(const ByteVector &data) { - ByteVectorList fields = ByteVectorList::split(data, char(0)); - - if(fields.size() != 2) + if(data.size() < 1) { + debug("An UFID frame must contain at least 1 byte."); return; + } - d->owner = fields.front(); - d->identifier = fields.back(); + int pos = 0; + d->owner = readStringField(data, String::Latin1, &pos); + d->identifier = data.mid(pos); } ByteVector UniqueFileIdentifierFrame::renderFields() const diff --git a/tests/test_id3v2.cpp b/tests/test_id3v2.cpp index e4ead22a..bfdf84bb 100644 --- a/tests/test_id3v2.cpp +++ b/tests/test_id3v2.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -34,6 +35,8 @@ class TestID3v2 : public CppUnit::TestFixture CPPUNIT_TEST(testParseAPIC); CPPUNIT_TEST(testParseGEOB); CPPUNIT_TEST(testParseRelativeVolumeFrame); + CPPUNIT_TEST(testParseUniqueFileIdentifierFrame); + CPPUNIT_TEST(testParseEmptyUniqueFileIdentifierFrame); CPPUNIT_TEST(testBrokenFrame1); //CPPUNIT_TEST(testItunes24FrameSize); CPPUNIT_TEST_SUITE_END(); @@ -135,6 +138,34 @@ public: f.peakVolume(ID3v2::RelativeVolumeFrame::FrontRight).peakVolume); } + void testParseUniqueFileIdentifierFrame() + { + ID3v2::UniqueFileIdentifierFrame f( + ByteVector("UFID" // Frame ID + "\x00\x00\x00\x09" // Frame size + "\x00\x00" // Frame flags + "owner\x00" // Owner identifier + "\x00\x01\x02", 19)); // Identifier + CPPUNIT_ASSERT_EQUAL(String("owner"), + f.owner()); + CPPUNIT_ASSERT_EQUAL(ByteVector("\x00\x01\x02", 3), + f.identifier()); + } + + void testParseEmptyUniqueFileIdentifierFrame() + { + ID3v2::UniqueFileIdentifierFrame f( + ByteVector("UFID" // Frame ID + "\x00\x00\x00\x01" // Frame size + "\x00\x00" // Frame flags + "\x00" // Owner identifier + "", 11)); // Identifier + CPPUNIT_ASSERT_EQUAL(String(), + f.owner()); + CPPUNIT_ASSERT_EQUAL(ByteVector(), + f.identifier()); + } + /*void testItunes24FrameSize() { MPEG::File f("data/005411.id3", false);