From: David Bryant <david@wavpack.com> Date: Sun, 26 Aug 2018 21:25:38 -0700 Subject: issue #43: catch zero channel count in DSF and DSDIFF files --- cli/dsdiff.c | 6 ++++++ cli/dsf.c | 1 + 2 files changed, 7 insertions(+) diff --git a/cli/dsdiff.c b/cli/dsdiff.c index c65aed3..738a46b 100644 --- a/cli/dsdiff.c +++ b/cli/dsdiff.c @@ -204,6 +204,12 @@ int ParseDsdiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa chansSpecified = (int)(dff_chunk_header.ckDataSize - sizeof (numChannels)) / 4; + if (numChannels < chansSpecified || numChannels < 1) { + error_line ("%s is not a valid .DFF file!", infilename); + free (prop_chunk); + return WAVPACK_SOFT_ERROR; + } + while (chansSpecified--) { if (!strncmp (cptr, "SLFT", 4) || !strncmp (cptr, "MLFT", 4)) chanMask |= 0x1; diff --git a/cli/dsf.c b/cli/dsf.c index cd82ae9..d12e409 100644 --- a/cli/dsf.c +++ b/cli/dsf.c @@ -122,6 +122,7 @@ int ParseDsfHeaderConfig (FILE *infile, char *infilename, char *fourcc, WavpackC if (format_chunk.ckSize != sizeof (DSFFormatChunk) || format_chunk.formatVersion != 1 || format_chunk.formatID != 0 || format_chunk.blockSize != DSF_BLOCKSIZE || format_chunk.reserved || (format_chunk.bitsPerSample != 1 && format_chunk.bitsPerSample != 8) || + format_chunk.numChannels < 1 || format_chunk.numChannels > 6 || format_chunk.chanType < 1 || format_chunk.chanType > NUM_CHAN_TYPES) { error_line ("%s is not a valid .DSF file!", infilename); return WAVPACK_SOFT_ERROR;