]> granicus.if.org Git - taglib/commitdiff
Call fflush() before ftruncate() to drop all buffered data (#914)
authorwhatdoineed2do <whatdoineed2do@gmail.com>
Thu, 25 Jul 2019 02:57:49 +0000 (03:57 +0100)
committerStephen F. Booth <me@sbooth.org>
Thu, 25 Jul 2019 02:57:49 +0000 (07:27 +0430)
This avoids stale data presented to caller via a fread()

Current bug due to the buffered data can be seen in stripping mp3s of tags

    f.strip(ID3v1);
    f.strip(APE);

The ID3v1 tag sits at the end of file (strip calls ftruncate()) and the APE
strip performs a readFile() that would return the stream buffered/truncated data
and reinsert

taglib/toolkit/tfilestream.cpp

index 487df8e3965397d9e2a1d18e30e0ace190d8a52d..20e1dfbc67fa4a4073bb7f88091bc85340f9b6ba 100644 (file)
@@ -493,6 +493,7 @@ void FileStream::truncate(long length)
 
 #else
 
+  fflush(d->file);
   const int error = ftruncate(fileno(d->file), length);
   if(error != 0)
     debug("FileStream::truncate() -- Coundn't truncate the file.");