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

wav: fix for extra padding bytes in fmt chunk for PCM #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions src/wav.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,47 +659,49 @@ static int wav_read_fmt(sox_format_t *ft, uint32_t len)
*/
if (wav->formatTag != WAVE_FORMAT_PCM &&
wav->formatTag != WAVE_FORMAT_ALAW &&
wav->formatTag != WAVE_FORMAT_MULAW &&
len < 2)
lsx_warn("WAVE file missing extended part of fmt chunk");
wav->formatTag != WAVE_FORMAT_MULAW)
{
if (len < 2)
lsx_warn("WAVE file missing extended part of fmt chunk");

if (len >= 2) {
err = lsx_read_fields(ft, &len, "h", &wExtSize);
if (err)
if (len >= 2) {
err = lsx_read_fields(ft, &len, "h", &wExtSize);
if (err)
return SOX_EOF;
}

if (wExtSize != len) {
lsx_fail_errno(ft, SOX_EOF,
"WAVE header error: cbSize inconsistent with fmt size");
return SOX_EOF;
}
}

if (wExtSize != len) {
lsx_fail_errno(ft, SOX_EOF,
"WAVE header error: cbSize inconsistent with fmt size");
return SOX_EOF;
}
if (wav->formatTag == WAVE_FORMAT_EXTENSIBLE) {
uint16_t numberOfValidBits;
uint32_t speakerPositionMask;
uint16_t subFormatTag;

if (wav->formatTag == WAVE_FORMAT_EXTENSIBLE) {
uint16_t numberOfValidBits;
uint32_t speakerPositionMask;
uint16_t subFormatTag;
if (len < 22) {
lsx_fail_errno(ft, SOX_EHDR, "WAVE file fmt chunk is too short");
return SOX_EOF;
}

if (len < 22) {
lsx_fail_errno(ft, SOX_EHDR, "WAVE file fmt chunk is too short");
return SOX_EOF;
}
err = lsx_read_fields(ft, &len, "hih14x",
&numberOfValidBits,
&speakerPositionMask,
&subFormatTag);
if (err)
return SOX_EOF;

err = lsx_read_fields(ft, &len, "hih14x",
&numberOfValidBits,
&speakerPositionMask,
&subFormatTag);
if (err)
return SOX_EOF;
if (numberOfValidBits > wav->bitsPerSample) {
lsx_fail_errno(ft, SOX_EHDR,
"wValidBitsPerSample > wBitsPerSample");
return SOX_EOF;
}

if (numberOfValidBits > wav->bitsPerSample) {
lsx_fail_errno(ft, SOX_EHDR,
"wValidBitsPerSample > wBitsPerSample");
return SOX_EOF;
wav->formatTag = subFormatTag;
lsx_report("EXTENSIBLE");
}

wav->formatTag = subFormatTag;
lsx_report("EXTENSIBLE");
}

/* User options take precedence */
Expand Down