avformat/nistspheredec: Check bits_per_coded_sample and channels

Fixes: signed integer overflow: 80 * 92233009 cannot be represented in type 'int'
Fixes: 26910/clusterfuzz-testcase-minimized-ffmpeg_dem_NISTSPHERE_fuzzer-6669100654919680

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Michael Niedermayer 2021-01-17 00:07:26 +01:00
parent 631ee3f8e4
commit 60770a50fb

View File

@ -90,6 +90,8 @@ static int nist_read_header(AVFormatContext *s)
return 0;
} else if (!memcmp(buffer, "channel_count", 13)) {
sscanf(buffer, "%*s %*s %u", &st->codecpar->channels);
if (st->codecpar->channels <= 0 || st->codecpar->channels > INT16_MAX)
return AVERROR_INVALIDDATA;
} else if (!memcmp(buffer, "sample_byte_format", 18)) {
sscanf(buffer, "%*s %*s %31s", format);
@ -109,12 +111,14 @@ static int nist_read_header(AVFormatContext *s)
sscanf(buffer, "%*s %*s %"SCNd64, &st->duration);
} else if (!memcmp(buffer, "sample_n_bytes", 14)) {
sscanf(buffer, "%*s %*s %d", &bps);
if (bps > INT_MAX/8U)
if (bps > INT16_MAX/8U)
return AVERROR_INVALIDDATA;
} else if (!memcmp(buffer, "sample_rate", 11)) {
sscanf(buffer, "%*s %*s %d", &st->codecpar->sample_rate);
} else if (!memcmp(buffer, "sample_sig_bits", 15)) {
sscanf(buffer, "%*s %*s %d", &st->codecpar->bits_per_coded_sample);
if (st->codecpar->bits_per_coded_sample <= 0 || st->codecpar->bits_per_coded_sample > INT16_MAX)
return AVERROR_INVALIDDATA;
} else {
char key[32], value[32];
if (sscanf(buffer, "%31s %*s %31s", key, value) == 2) {