mvdec: check channel count.
Fixes division by 0 Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
e6cc3c869b
commit
b89815f519
@ -88,6 +88,16 @@ static void var_read_metadata(AVFormatContext *avctx, const char *tag, int size)
|
|||||||
av_dict_set(&avctx->metadata, tag, value, AV_DICT_DONT_STRDUP_VAL);
|
av_dict_set(&avctx->metadata, tag, value, AV_DICT_DONT_STRDUP_VAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int set_channels(AVFormatContext *avctx, AVStream *st, int channels) {
|
||||||
|
if (channels <= 0) {
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "Channel count %d invalid\n", channels);
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
|
st->codec->channels = channels;
|
||||||
|
st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse global variable
|
* Parse global variable
|
||||||
* @return < 0 if unknown
|
* @return < 0 if unknown
|
||||||
@ -126,8 +136,7 @@ static int parse_audio_var(AVFormatContext *avctx, AVStream *st, const char *nam
|
|||||||
} else if (!strcmp(name, "DEFAULT_VOL")) {
|
} else if (!strcmp(name, "DEFAULT_VOL")) {
|
||||||
var_read_metadata(avctx, name, size);
|
var_read_metadata(avctx, name, size);
|
||||||
} else if (!strcmp(name, "NUM_CHANNELS")) {
|
} else if (!strcmp(name, "NUM_CHANNELS")) {
|
||||||
st->codec->channels = var_read_int(pb, size);
|
return set_channels(avctx, st, var_read_int(pb, size));
|
||||||
st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
|
|
||||||
} else if (!strcmp(name, "SAMPLE_RATE")) {
|
} else if (!strcmp(name, "SAMPLE_RATE")) {
|
||||||
st->codec->sample_rate = var_read_int(pb, size);
|
st->codec->sample_rate = var_read_int(pb, size);
|
||||||
avpriv_set_pts_info(st, 33, 1, st->codec->sample_rate);
|
avpriv_set_pts_info(st, 33, 1, st->codec->sample_rate);
|
||||||
@ -275,8 +284,9 @@ static int mv_read_header(AVFormatContext *avctx)
|
|||||||
ast->nb_frames = vst->nb_frames;
|
ast->nb_frames = vst->nb_frames;
|
||||||
ast->codec->sample_rate = avio_rb32(pb);
|
ast->codec->sample_rate = avio_rb32(pb);
|
||||||
avpriv_set_pts_info(ast, 33, 1, ast->codec->sample_rate);
|
avpriv_set_pts_info(ast, 33, 1, ast->codec->sample_rate);
|
||||||
ast->codec->channels = avio_rb32(pb);
|
if (set_channels(avctx, ast, avio_rb32(pb)) < 0)
|
||||||
ast->codec->channel_layout = (ast->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
|
return AVERROR_INVALIDDATA;
|
||||||
|
|
||||||
v = avio_rb32(pb);
|
v = avio_rb32(pb);
|
||||||
if (v == AUDIO_FORMAT_SIGNED) {
|
if (v == AUDIO_FORMAT_SIGNED) {
|
||||||
ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
|
ast->codec->codec_id = AV_CODEC_ID_PCM_S16BE;
|
||||||
@ -322,6 +332,10 @@ static int mv_read_header(AVFormatContext *avctx)
|
|||||||
ast->codec->codec_id = AV_CODEC_ID_NONE;
|
ast->codec->codec_id = AV_CODEC_ID_NONE;
|
||||||
}
|
}
|
||||||
ast->codec->codec_tag = 0;
|
ast->codec->codec_tag = 0;
|
||||||
|
if (ast->codec->channels <= 0) {
|
||||||
|
av_log(avctx, AV_LOG_ERROR, "No valid channel count found\n");
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mv->nb_video_tracks > 1) {
|
if (mv->nb_video_tracks > 1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user