library usage feedback

Николай Шафоростов shafff at ukr.net
Mon Jan 17 12:44:16 CET 2011


The following changes to taglib may be interesting for you:
*on unix we had to change wchar_t to wchar
*in taglib/taglib/asf/asffile.cpp changed ASF::File::BaseObject::parse() function body to
	data.clear();
	if (size > 24 && size <= file->length())
		data = file->readBlock(size - 24);
	else
		data = ByteVector::null;


also the following workaround needed to be done in order to stop taglib consuming megs and megs on parsing some wma files (it seems it loaded complete file into memory as unknown object):
Index: asffile.cpp
===================================================================
--- asffile.cpp	(revision 13561)
+++ asffile.cpp	(revision 13562)
@@ -340,7 +340,7 @@
   while(dataPos < dataSize) {
     ByteVector guid = file->readBlock(16);
     long long size = file->readQWORD();
-    BaseObject *obj;
+    BaseObject *obj = 0;
     if(guid == metadataGuid) {
       obj = new MetadataObject();
     }
@@ -348,10 +348,13 @@
       obj = new MetadataLibraryObject();
     }
     else {
-      obj = new UnknownObject(guid);
+      //obj = new UnknownObject(guid);
     }
-    obj->parse(file, size);
-    objects.append(obj);
+	if (obj)
+	{
+		obj->parse(file, size);
+		objects.append(obj);
+	}
     dataPos += size;
   }
 }
@@ -424,7 +427,7 @@
   for(int i = 0; i < numObjects; i++) {
     ByteVector guid = readBlock(16);
     long size = (long)readQWORD();
-    BaseObject *obj;
+    BaseObject *obj = 0;
     if(guid == filePropertiesGuid) {
       obj = new FilePropertiesObject();
     }
@@ -441,10 +444,13 @@
       obj = new HeaderExtensionObject();
     }
     else {
-      obj = new UnknownObject(guid);
+      //obj = new UnknownObject(guid);
     }
-    obj->parse(this, size);
-    d->objects.append(obj);
+	if (obj)
+	{
+		obj->parse(this, size);
+		d->objects.append(obj);
+	}
   }
 }
 


i experienced crashes with TagLib::String::toCString() function, i didn't like TStringToQString macro beacuse it converts TagLib::String from utf16 to utf8 and then this conversion is done backwards (from utf8 to utf16) by QString::fromUtf8 method, so i wrote my own converter:

#ifdef TStringToQString
#undef TStringToQString
#endif
QString TStringToQString(TagLib::String s)
{
	if (s.isLatin1()) //respect the tradition of writing data in system locale when no encoding is defined
	{
		QByteArray result;
		result.resize(s.size());
		for (int i=0;i<result.size();i++)
			result[i]=s[i];

		return QTextCodec::codecForLocale()->toUnicode(result);
	}

	QString result;
	result.resize(s.size());
	for (int i=0;i<result.size();i++)
		result[i]=s[i];

	return result;
}



More information about the taglib-devel mailing list