Skip to content

Commit

Permalink
Added extra checks in read_wav_file
Browse files Browse the repository at this point in the history
  • Loading branch information
randaz81 committed Nov 24, 2023
1 parent b5f93e8 commit 5b70147
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libYARP_sig/src/yarp/sig/SoundFileWav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,33 @@ bool PcmWavHeader::parse_from_file(FILE *fp)
yCError(SOUNDFILE_WAV, "failed to read .wav file");
return false;
}
if (pcm.pcmChannels <= 0)
{
yCError(SOUNDFILE_WAV, "pcmChannels <=0, invalid wav file\n");
return false;
}

ret = fread(&pcm.pcmSamplesPerSecond, sizeof(pcm.pcmSamplesPerSecond), 1, fp);
if (ret != 1) {
yCError(SOUNDFILE_WAV, "failed to read .wav file");
return false;
}
if (pcm.pcmSamplesPerSecond <= 0)
{
yCError(SOUNDFILE_WAV, "pcmSamplesPerSecond <=0, invalid wav file\n");
return false;
}

ret = fread(&pcm.pcmBytesPerSecond, sizeof(pcm.pcmBytesPerSecond), 1, fp);
if (ret != 1) {
yCError(SOUNDFILE_WAV, "failed to read .wav file");
return false;
}
if (pcm.pcmBytesPerSecond <= 0)
{
yCError(SOUNDFILE_WAV, "pcmBytesPerSecond <=0, invalid wav file\n");
return false;
}

ret = fread(&pcm.pcmBlockAlign, sizeof(pcm.pcmBlockAlign), 1, fp);
if (ret != 1) {
Expand Down

0 comments on commit 5b70147

Please sign in to comment.