Skip to content

Commit

Permalink
fix potential crash where empty data array can be passed to the library
Browse files Browse the repository at this point in the history
  • Loading branch information
adamstark committed May 18, 2023
1 parent 2a96219 commit f46a4e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions AudioFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,9 @@ void AudioFile<T>::clearAudioBuffer()
template <class T>
AudioFileFormat AudioFile<T>::determineAudioFileFormat (const std::vector<uint8_t>& fileData)
{
if (fileData.size() < 4)
return AudioFileFormat::Error;

std::string header (fileData.begin(), fileData.begin() + 4);

if (header == "RIFF")
Expand Down
9 changes: 9 additions & 0 deletions tests/GeneralTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ TEST_SUITE ("General Tests")

checkFilesAreExactlyTheSame<int16_t> (a, b);
}

//=============================================================
TEST_CASE ("GeneralTests::Empty Data")
{
AudioFile<float> a;
a.shouldLogErrorsToConsole (false);
bool result = a.loadFromMemory (std::vector<uint8_t>());
CHECK_EQ (result, false);
}
}

0 comments on commit f46a4e4

Please sign in to comment.