diff --git a/AudioFile.h b/AudioFile.h index aa33f50..36bb41d 100644 --- a/AudioFile.h +++ b/AudioFile.h @@ -1245,6 +1245,9 @@ void AudioFile::clearAudioBuffer() template AudioFileFormat AudioFile::determineAudioFileFormat (const std::vector& fileData) { + if (fileData.size() < 4) + return AudioFileFormat::Error; + std::string header (fileData.begin(), fileData.begin() + 4); if (header == "RIFF") diff --git a/tests/GeneralTests.cpp b/tests/GeneralTests.cpp index cc0ff39..705a5b5 100644 --- a/tests/GeneralTests.cpp +++ b/tests/GeneralTests.cpp @@ -107,4 +107,13 @@ TEST_SUITE ("General Tests") checkFilesAreExactlyTheSame (a, b); } + + //============================================================= + TEST_CASE ("GeneralTests::Empty Data") + { + AudioFile a; + a.shouldLogErrorsToConsole (false); + bool result = a.loadFromMemory (std::vector()); + CHECK_EQ (result, false); + } }