Skip to content

Commit

Permalink
Merge remote-tracking branch 'official/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Helmling committed Oct 30, 2011
2 parents 772bc9f + 6ea8599 commit 292a377
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Expand Up @@ -11,6 +11,11 @@ else()
endif()
OPTION(ENABLE_STATIC_RUNTIME "Visual Studio, link with runtime statically" OFF)

option(VISIBILITY_HIDDEN "Build with -fvisibility=hidden" OFF)
if(VISIBILITY_HIDDEN)
add_definitions (-fvisibility=hidden)
endif()

option(BUILD_TESTS "Build the test suite" OFF)
option(BUILD_EXAMPLES "Build the examples" OFF)

Expand Down
5 changes: 5 additions & 0 deletions taglib/riff/aiff/aifffile.cpp
Expand Up @@ -95,6 +95,11 @@ bool RIFF::AIFF::File::save()
return false;
}

if(!isValid()) {
debug("RIFF::AIFF::File::save() -- Trying to save invalid file.");
return false;
}

setChunkData(d->tagChunkID, d->tag->render());

return true;
Expand Down
22 changes: 21 additions & 1 deletion taglib/riff/rifffile.cpp
Expand Up @@ -203,6 +203,19 @@ void RIFF::File::setChunkData(const ByteVector &name, const ByteVector &data)
// private members
////////////////////////////////////////////////////////////////////////////////

static bool isValidChunkID(const ByteVector &name)
{
if(name.size() != 4) {
return false;
}
for(int i = 0; i < 4; i++) {
if(name[i] < 32 || name[i] > 127) {
return false;
}
}
return true;
}

void RIFF::File::read()
{
bool bigEndian = (d->endianness == BigEndian);
Expand All @@ -216,8 +229,15 @@ void RIFF::File::read()
ByteVector chunkName = readBlock(4);
uint chunkSize = readBlock(4).toUInt(bigEndian);

if(!isValidChunkID(chunkName)) {
debug("RIFF::File::read() -- Chunk '" + chunkName + "' has invalid ID");
setValid(false);
break;
}

if(tell() + chunkSize > uint(length())) {
// something wrong
debug("RIFF::File::read() -- Chunk '" + chunkName + "' has invalid size (larger than the file size)");
setValid(false);
break;
}

Expand Down
5 changes: 5 additions & 0 deletions taglib/riff/wav/wavfile.cpp
Expand Up @@ -95,6 +95,11 @@ bool RIFF::WAV::File::save()
return false;
}

if(!isValid()) {
debug("RIFF::WAV::File::save() -- Trying to save invalid file.");
return false;
}

setChunkData(d->tagChunkID, d->tag->render());

return true;
Expand Down
Binary file added tests/data/zero-size-chunk.wav
Binary file not shown.
8 changes: 8 additions & 0 deletions tests/test_wav.cpp
Expand Up @@ -13,16 +13,24 @@ class TestWAV : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(TestWAV);
CPPUNIT_TEST(testLength);
CPPUNIT_TEST(testZeroSizeDataChunk);
CPPUNIT_TEST_SUITE_END();

public:

void testLength()
{
RIFF::WAV::File f(TEST_FILE_PATH_C("empty.wav"));
CPPUNIT_ASSERT_EQUAL(true, f.isValid());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
}

void testZeroSizeDataChunk()
{
RIFF::WAV::File f(TEST_FILE_PATH_C("zero-size-chunk.wav"));
CPPUNIT_ASSERT_EQUAL(false, f.isValid());
}

};

CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV);

0 comments on commit 292a377

Please sign in to comment.