Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made WAV file reader no longer assume that data chunk goes till end of file to prevent reading trailing metadata as samples. #1018

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/SFML/Audio/SoundFileReaderWav.cpp
Expand Up @@ -110,7 +110,8 @@ bool SoundFileReaderWav::check(InputStream& stream)
SoundFileReaderWav::SoundFileReaderWav() :
m_stream (NULL),
m_bytesPerSample(0),
m_dataStart (0)
m_dataStart (0),
m_dataEnd (0)
{
}

Expand Down Expand Up @@ -145,7 +146,7 @@ Uint64 SoundFileReaderWav::read(Int16* samples, Uint64 maxCount)
assert(m_stream);

Uint64 count = 0;
while (count < maxCount)
while ((count < maxCount) && (m_stream->tell() < m_dataEnd))
{
switch (m_bytesPerSample)
{
Expand Down Expand Up @@ -285,8 +286,9 @@ bool SoundFileReaderWav::parseHeader(Info& info)
// Compute the total number of samples
info.sampleCount = subChunkSize / m_bytesPerSample;

// Store the starting position of samples in the file
// Store the start and end position of samples in the file
m_dataStart = m_stream->tell();
m_dataEnd = m_dataStart + info.sampleCount * m_bytesPerSample;

dataChunkFound = true;
}
Expand Down
1 change: 1 addition & 0 deletions src/SFML/Audio/SoundFileReaderWav.hpp
Expand Up @@ -111,6 +111,7 @@ class SoundFileReaderWav : public SoundFileReader
InputStream* m_stream; ///< Source stream to read from
unsigned int m_bytesPerSample; ///< Size of a sample, in bytes
Uint64 m_dataStart; ///< Starting position of the audio data in the open file
Uint64 m_dataEnd; ///< Position one byte past the end of the audio data in the open file
};

} // namespace priv
Expand Down