another TagLib crash in STL due 0-length string

David Lasker dave at altosdesign.com
Tue Jun 5 04:03:28 CEST 2007


I found a similar error in tfile.cpp method File::removeBlock when deleting
an APE v2 tag.

There is a loop reading through end-of-file, but it tries to do all its
stuff the last time through the loop when zero bytes were read. The STL
error occurs on line 420

	fwrite(buffer.data(), ...

when buffer is of zero length

Here's my patch to fix it:

Index: tfile.cpp
===================================================================
--- tfile.cpp   (revision 671570)
+++ tfile.cpp   (working copy)
@@ -402,11 +402,9 @@

   ByteVector buffer(static_cast<uint>(bufferLength));

-  ulong bytesRead = true;
-
-  while(bytesRead != 0) {
+  for(;;) {
     seek(readPosition);
-    bytesRead = fread(buffer.data(), sizeof(char), bufferLength, d->file);
+    uint bytesRead = fread(buffer.data(), sizeof(char), bufferLength,
d->file);
     buffer.resize(bytesRead);
     readPosition += bytesRead;

@@ -416,6 +414,9 @@
     if(bytesRead < bufferLength)
       clear();

+    if (bytesRead == 0)
+        break;
+
     seek(writePosition);
     fwrite(buffer.data(), sizeof(char), bytesRead, d->file);
     writePosition += bytesRead;

Would Michael or someone else be willing to commit this (or similar) change?

Thanks for the help!

Dave

-----Original Message-----
From: Michael Pyne [mailto:michael.pyne at kdemail.net] 
Sent: Saturday, May 26, 2007 4:01 PM
To: taglib-devel at kde.org
Subject: Re: TagLib crash in STL due to append of zero-length GEOB filename

On Saturday 26 May 2007, David Lasker wrote:
> I'm a bit of a newbie to ID3 and TagLib, so if there is something I can do
> in my code to avoid this problem please let me know. Otherwise could some
> kind soul apply this patch (corrected if necessary) to the repository?

Fixed in revision 668610 (but please test)

Index: tbytevector.cpp
===================================================================
--- tbytevector.cpp     (revision 668609)
+++ tbytevector.cpp     (working copy)
@@ -432,6 +432,9 @@

 ByteVector &ByteVector::append(const ByteVector &v)
 {
+  if(v.d->size == 0)
+    return *this; // Simply return if appending nothing.
+
   detach();

   uint originalSize = d->size;

Regards,
 - Michael Pyne
_______________________________________________
taglib-devel mailing list
taglib-devel at kde.org
https://mail.kde.org/mailman/listinfo/taglib-devel



More information about the taglib-devel mailing list