Rediffed from http://git.videolan.org/?p=ffmpeg.git;a=blobdiff;f=libavcodec/utils.c;h=c31608df99644d1c27a92555409c6a3eb9383d42;hp=1ec039e5e99bbffd1a3ed9d5004e518b7eddc14d;hb=4c0dda2b3f45471faa233c62205e712fb072a76b;hpb=6e3fa35d295ff6038cfcac0e03000769f0c656d5 http://git.videolan.org/?p=ffmpeg.git;a=blobdiff;f=libavcodec/utils.c;h=4ab0c350ee4438bfa3184790da0b84a528a556c8;hp=c31608df99644d1c27a92555409c6a3eb9383d42;hb=2a9b5c9b429d4162f449771a5043310b3f4acc06;hpb=aedc98b0a4ee434aa54908b815f78a4c563c1d31 http://git.videolan.org/?p=ffmpeg.git;a=blobdiff;f=libavcodec/utils.c;h=c3df903f1e161c2e3829aa84c3780778747e5817;hp=4ab0c350ee4438bfa3184790da0b84a528a556c8;hb=681c180dc441bf9fea1bb363c75c5d443f11a53a;hpb=43d7c6118d64a8b2772e2d9e0c13413968e776f1 --- libavcodec/utils.c.CVE-2009-4635 2011-03-21 15:37:21.000000000 +0100 +++ libavcodec/utils.c 2011-03-21 15:48:09.000000000 +0100 @@ -818,26 +818,35 @@ int attribute_align_arg avcodec_open(AVC avcodec_set_dimensions(avctx, avctx->width, avctx->height); if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){ - av_freep(&avctx->priv_data); ret = AVERROR(EINVAL); - goto end; + goto free_and_end; } avctx->codec = codec; - avctx->codec_id = codec->id; + if ((avctx->codec_type == CODEC_TYPE_UNKNOWN || avctx->codec_type == codec->type) && + avctx->codec_id == CODEC_ID_NONE) { + avctx->codec_type = codec->type; + avctx->codec_id = codec->id; + } + if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){ + av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n"); + goto free_and_end; + } avctx->frame_number = 0; if(avctx->codec->init){ ret = avctx->codec->init(avctx); if (ret < 0) { - av_freep(&avctx->priv_data); - avctx->codec= NULL; - goto end; + goto free_and_end; } } ret=0; end: entangled_thread_counter--; return ret; +free_and_end: + av_freep(&avctx->priv_data); + avctx->codec = NULL; + goto end; } int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,