Merge pull request #612 from TsudaKageyu/flac-id3v1

Avoid overwriting the audio stream when adding an ID3v1 tag to a FLAC…
This commit is contained in:
Tsuda Kageyu 2015-08-03 15:54:16 +09:00
commit f112d538ea
3 changed files with 35 additions and 1 deletions

1
NEWS
View File

@ -36,6 +36,7 @@ TagLib 1.10 (??? ??, 2015)
* New API for the audio length in milliseconds.
* Marked FLAC::File::streamInfoData() deprecated. It returns an empty ByteVector.
* Marked FLAC::File::streamLength() deprecated. It returns zero.
* Fixed possible file corruptions when adding an ID3v1 tag to FLAC files.
* Many smaller bug fixes and performance improvements.
TagLib 1.9.1 (Oct 8, 2013)

View File

@ -258,8 +258,16 @@ bool FLAC::File::save()
}
if(ID3v1Tag()) {
seek(-128, End);
if(d->hasID3v1) {
seek(d->ID3v1Location);
}
else {
seek(0, End);
d->ID3v1Location = tell();
}
writeBlock(ID3v1Tag()->render());
d->hasID3v1 = true;
}
return true;

View File

@ -6,6 +6,7 @@
#include <tpropertymap.h>
#include <flacfile.h>
#include <xiphcomment.h>
#include <id3v1tag.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
@ -27,6 +28,7 @@ class TestFLAC : public CppUnit::TestFixture
CPPUNIT_TEST(testInvalid);
CPPUNIT_TEST(testAudioProperties);
CPPUNIT_TEST(testZeroSizedPadding);
CPPUNIT_TEST(testSaveID3v1);
CPPUNIT_TEST_SUITE_END();
public:
@ -283,6 +285,29 @@ public:
CPPUNIT_ASSERT(f.isValid());
}
void testSaveID3v1()
{
ScopedFileCopy copy("no-tags", ".flac");
ByteVector audioStream;
{
FLAC::File f(copy.fileName().c_str());
CPPUNIT_ASSERT(!f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL((long)4692, f.length());
f.seek(0x0100);
audioStream = f.readBlock(4436);
f.ID3v1Tag(true)->setTitle("01234 56789 ABCDE FGHIJ");
f.save();
CPPUNIT_ASSERT(f.hasID3v1Tag());
CPPUNIT_ASSERT_EQUAL((long)4820, f.length());
f.seek(0x0100);
CPPUNIT_ASSERT_EQUAL(audioStream, f.readBlock(4436));
}
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestFLAC);