return false;
}
+ if(!isValid()) {
+ debug("RIFF::AIFF::File::save() -- Trying to save invalid file.");
+ return false;
+ }
+
setChunkData(d->tagChunkID, d->tag->render());
return true;
// 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);
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;
}
return false;
}
+ if(!isValid()) {
+ debug("RIFF::WAV::File::save() -- Trying to save invalid file.");
+ return false;
+ }
+
setChunkData(d->tagChunkID, d->tag->render());
return true;
{
CPPUNIT_TEST_SUITE(TestWAV);
CPPUNIT_TEST(testLength);
+ CPPUNIT_TEST(testZeroSizeDataChunk);
CPPUNIT_TEST_SUITE_END();
public:
void testLength()
{
RIFF::WAV::File f("data/empty.wav");
+ CPPUNIT_ASSERT_EQUAL(true, f.isValid());
CPPUNIT_ASSERT_EQUAL(3, f.audioProperties()->length());
}
+ void testZeroSizeDataChunk()
+ {
+ RIFF::WAV::File f("data/zero-size-chunk.wav");
+ CPPUNIT_ASSERT_EQUAL(false, f.isValid());
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(TestWAV);