diff options
author | Urs Fleisch <ufleisch@users.sourceforge.net> | 2020-12-06 08:56:35 +0100 |
---|---|---|
committer | Urs Fleisch <ufleisch@users.sourceforge.net> | 2020-12-06 08:56:35 +0100 |
commit | 2dd6931eee2ab502cb636d96357b885eaec5084a (patch) | |
tree | d21cd7cbab2d0d9d0beec99fa6b84041bc485775 /tests | |
parent | 91b00b17b253dad0d7037232ef7033c88bdd28bd (diff) |
Accept WAV files with garbage appended (#973)
This will allow editing the tags of WAV files which have data
appended at the end. The corresponding unit test checks that the
original contents are still available after editing the metadata
of such files.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_aiff.cpp | 4 | ||||
-rw-r--r-- | tests/test_wav.cpp | 46 |
2 files changed, 46 insertions, 4 deletions
diff --git a/tests/test_aiff.cpp b/tests/test_aiff.cpp index 116c13a6..0337729f 100644 --- a/tests/test_aiff.cpp +++ b/tests/test_aiff.cpp @@ -148,13 +148,13 @@ public: void testFuzzedFile1() { RIFF::AIFF::File f(TEST_FILE_PATH_C("segfault.aif")); - CPPUNIT_ASSERT(!f.isValid()); + CPPUNIT_ASSERT(f.isValid()); } void testFuzzedFile2() { RIFF::AIFF::File f(TEST_FILE_PATH_C("excessive_alloc.aif")); - CPPUNIT_ASSERT(!f.isValid()); + CPPUNIT_ASSERT(f.isValid()); } }; diff --git a/tests/test_wav.cpp b/tests/test_wav.cpp index fd0c04f7..c0717398 100644 --- a/tests/test_wav.cpp +++ b/tests/test_wav.cpp @@ -28,6 +28,7 @@ #include <id3v2tag.h> #include <infotag.h> #include <tbytevectorlist.h> +#include <tfilestream.h> #include <tpropertymap.h> #include <wavfile.h> #include <cppunit/extensions/HelperMacros.h> @@ -50,6 +51,7 @@ class TestWAV : public CppUnit::TestFixture CPPUNIT_TEST(testDuplicateTags); CPPUNIT_TEST(testFuzzedFile1); CPPUNIT_TEST(testFuzzedFile2); + CPPUNIT_TEST(testFileWithGarbageAppended); CPPUNIT_TEST(testStripAndProperties); CPPUNIT_TEST(testPCMWithFactChunk); CPPUNIT_TEST_SUITE_END(); @@ -101,7 +103,7 @@ public: void testZeroSizeDataChunk() { RIFF::WAV::File f(TEST_FILE_PATH_C("zero-size-chunk.wav")); - CPPUNIT_ASSERT(!f.isValid()); + CPPUNIT_ASSERT(f.isValid()); } void testID3v2Tag() @@ -262,7 +264,17 @@ public: void testFuzzedFile1() { RIFF::WAV::File f1(TEST_FILE_PATH_C("infloop.wav")); - CPPUNIT_ASSERT(!f1.isValid()); + CPPUNIT_ASSERT(f1.isValid()); + // The file has problems: + // Chunk 'ISTt' has invalid size (larger than the file size). + // Its properties can nevertheless be read. + RIFF::WAV::Properties* properties = f1.audioProperties(); + CPPUNIT_ASSERT_EQUAL(1, properties->channels()); + CPPUNIT_ASSERT_EQUAL(88, properties->bitrate()); + CPPUNIT_ASSERT_EQUAL(8, properties->bitsPerSample()); + CPPUNIT_ASSERT_EQUAL(11025, properties->sampleRate()); + CPPUNIT_ASSERT(!f1.hasInfoTag()); + CPPUNIT_ASSERT(!f1.hasID3v2Tag()); } void testFuzzedFile2() @@ -271,6 +283,36 @@ public: CPPUNIT_ASSERT(f2.isValid()); } + void testFileWithGarbageAppended() + { + ScopedFileCopy copy("empty", ".wav"); + ByteVector contentsBeforeModification; + { + FileStream stream(copy.fileName().c_str()); + stream.seek(0, IOStream::End); + const char garbage[] = "12345678"; + stream.writeBlock(ByteVector(garbage, sizeof(garbage) - 1)); + stream.seek(0); + contentsBeforeModification = stream.readBlock(stream.length()); + } + { + RIFF::WAV::File f(copy.fileName().c_str()); + CPPUNIT_ASSERT(f.isValid()); + f.ID3v2Tag()->setTitle("ID3v2 Title"); + f.InfoTag()->setTitle("INFO Title"); + CPPUNIT_ASSERT(f.save()); + } + { + RIFF::WAV::File f(copy.fileName().c_str()); + f.strip(); + } + { + FileStream stream(copy.fileName().c_str()); + ByteVector contentsAfterModification = stream.readBlock(stream.length()); + CPPUNIT_ASSERT_EQUAL(contentsBeforeModification, contentsAfterModification); + } + } + void testStripAndProperties() { ScopedFileCopy copy("empty", ".wav"); |