[PATCH] Fix handling of ID3v2.3 text frames
Xavier Duret
xaviour.maillists at gmail.com
Fri Jan 19 16:35:36 CET 2007
This update of the previous patch also get rid of trailing zeros that
are allowed in ID3v2.3. Trailing zeros is not a common behavior but I
do have an example of it.
diff -ruN taglib.old/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
taglib/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
--- taglib.old/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
2007-01-17 16:01:34.000000000 +0100
+++ taglib/taglib/mpeg/id3v2/frames/textidentificationframe.cpp
2007-01-19 14:40:56.000000000 +0100
@@ -94,16 +94,26 @@
void TextIdentificationFrame::parseFields(const ByteVector &data)
{
+ ByteVector fixedData;
+ uint i = 0;
+
// read the string data type (the first byte of the field data)
d->textEncoding = String::Type(data[0]);
+ int byteAlign = d->textEncoding == String::Latin1 ||
d->textEncoding == String::UTF8 ? 1 : 2;
+
+ // Strip trailing zeros for ID3v2.3
+
+ while((i<data.size()) && (data.mid(data.size() - i - 1, 1) ==
ByteVector(1,0)))
+ i++;
+ if ((byteAlign == 2) && ((i % 2) == 1))
+ i--;
+ fixedData = data.mid(0, data.size() - i);
// split the byte array into chunks based on the string type (two
byte delimiter
// for unicode encodings)
- int byteAlign = d->textEncoding == String::Latin1 ||
d->textEncoding == String::UTF8 ? 1 : 2;
-
- ByteVectorList l = ByteVectorList::split(data.mid(1),
textDelimiter(d->textEncoding), byteAlign);
+ ByteVectorList l = ByteVectorList::split(fixedData.mid(1),
textDelimiter(d->textEncoding), byteAlign);
d->fieldList.clear();
On 1/17/07, Xavier Duret <xaviour.maillists at gmail.com> wrote:
> ID3v2.3 specifies that text information frames can be NULL terminated
> (see section 4.2). The encoding of the strings themselves are
> specified in section 3.3. This means that a frame like "54 52 43 4b 00
> 00 00 03 00 00 00 31 00 TRCK.......1." actually contains a single NULL
> terminated string.
> This patch makes ID3v2.3 text information frames behave like ID3v2.4
> which in turn ensures that the parsing of "TRCK" tag works properly
> (in the example, return 1 instead of 0).
More information about the taglib-devel
mailing list