aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2015-12-14 22:11:55 +0100
committerAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2015-12-20 16:13:15 +0100
commit6fc3f6f43b24b98a768acc28f03fec37ef1a79e3 (patch)
tree73592451d650d0ce62daa700bcdaa7501f73dd1e
parent7f33fef2a28dbc63ee98b0a217acabf760c5b7cd (diff)
downloadffmpeg-6fc3f6f43b24b98a768acc28f03fec37ef1a79e3.tar.gz
ffm: reject invalid codec_id and codec_type
A negative codec_id cannot be handled by the found_decoder API of AVStream->info: if the codec_id is not recognized, found_decoder is set to -codec_id, which has to be '<0' according to the API documentation. This can cause NULL pointer dereferencing in try_decode_frame. Also make sure the codec_type matches the expected one for codec_id. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> (cherry picked from commit ecf63b7cc24b9fd3e6d604313325dd1ada4db662) Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
-rw-r--r--libavformat/ffmdec.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libavformat/ffmdec.c b/libavformat/ffmdec.c
index 2753f2c2d3..ee3e1d6ea4 100644
--- a/libavformat/ffmdec.c
+++ b/libavformat/ffmdec.c
@@ -243,6 +243,7 @@ static int ffm2_read_header(AVFormatContext *s)
AVStream *st;
AVIOContext *pb = s->pb;
AVCodecContext *codec;
+ const AVCodecDescriptor *codec_desc;
int ret;
ffm->packet_size = avio_rb32(pb);
@@ -289,7 +290,20 @@ static int ffm2_read_header(AVFormatContext *s)
codec = st->codec;
/* generic info */
codec->codec_id = avio_rb32(pb);
+ codec_desc = avcodec_descriptor_get(codec->codec_id);
+ if (!codec_desc) {
+ av_log(s, AV_LOG_ERROR, "Invalid codec id: %d\n", codec->codec_id);
+ codec->codec_id = AV_CODEC_ID_NONE;
+ goto fail;
+ }
codec->codec_type = avio_r8(pb);
+ if (codec->codec_type != codec_desc->type) {
+ av_log(s, AV_LOG_ERROR, "Codec type mismatch: expected %d, found %d\n",
+ codec_desc->type, codec->codec_type);
+ codec->codec_id = AV_CODEC_ID_NONE;
+ codec->codec_type = AVMEDIA_TYPE_UNKNOWN;
+ goto fail;
+ }
codec->bit_rate = avio_rb32(pb);
codec->flags = avio_rb32(pb);
codec->flags2 = avio_rb32(pb);
@@ -389,6 +403,7 @@ static int ffm_read_header(AVFormatContext *s)
AVStream *st;
AVIOContext *pb = s->pb;
AVCodecContext *codec;
+ const AVCodecDescriptor *codec_desc;
int i, nb_streams;
uint32_t tag;
@@ -426,7 +441,20 @@ static int ffm_read_header(AVFormatContext *s)
codec = st->codec;
/* generic info */
codec->codec_id = avio_rb32(pb);
+ codec_desc = avcodec_descriptor_get(codec->codec_id);
+ if (!codec_desc) {
+ av_log(s, AV_LOG_ERROR, "Invalid codec id: %d\n", codec->codec_id);
+ codec->codec_id = AV_CODEC_ID_NONE;
+ goto fail;
+ }
codec->codec_type = avio_r8(pb); /* codec_type */
+ if (codec->codec_type != codec_desc->type) {
+ av_log(s, AV_LOG_ERROR, "Codec type mismatch: expected %d, found %d\n",
+ codec_desc->type, codec->codec_type);
+ codec->codec_id = AV_CODEC_ID_NONE;
+ codec->codec_type = AVMEDIA_TYPE_UNKNOWN;
+ goto fail;
+ }
codec->bit_rate = avio_rb32(pb);
codec->flags = avio_rb32(pb);
codec->flags2 = avio_rb32(pb);