aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2016-01-12 03:03:01 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2016-01-15 17:39:04 +0100
commit1c99807cb704cf923d9912688f22a413d7ce772b (patch)
treefb3ce436882ab1462296ad7b1b38b02d72a36399
parent4865d66b76f7bb85b837bcadb9f9d7b7337f137a (diff)
downloadffmpeg-1c99807cb704cf923d9912688f22a413d7ce772b.tar.gz
avcodec/mpeg4video: Check time_incr
Fixes assertion failure Fixes out of memory access Fixes: test_casex.ivf Found-by: Tyson Smith <twsmith@mozilla.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 7c97946d6131b31340954a3f603b6bf92590a9a5) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/mpeg4video.h2
-rw-r--r--libavcodec/mpeg4videoenc.c10
-rw-r--r--libavcodec/mpegvideo_enc.c8
3 files changed, 15 insertions, 5 deletions
diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index e83692cc87..fa92e999bd 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -137,7 +137,7 @@ void ff_mpeg4_encode_mb(MpegEncContext *s,
void ff_mpeg4_pred_ac(MpegEncContext *s, int16_t *block, int n,
int dir);
void ff_set_mpeg4_time(MpegEncContext *s);
-void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
+int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb);
void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
diff --git a/libavcodec/mpeg4videoenc.c b/libavcodec/mpeg4videoenc.c
index 5751432a31..c47b6e8410 100644
--- a/libavcodec/mpeg4videoenc.c
+++ b/libavcodec/mpeg4videoenc.c
@@ -1086,7 +1086,7 @@ static void mpeg4_encode_vol_header(MpegEncContext *s,
}
/* write mpeg4 VOP header */
-void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
+int ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
{
int time_incr;
int time_div, time_mod;
@@ -1112,6 +1112,12 @@ void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
time_mod = FFUMOD(s->time, s->avctx->time_base.den);
time_incr = time_div - s->last_time_base;
av_assert0(time_incr >= 0);
+
+ // This limits the frame duration to max 1 hour
+ if (time_incr > 3600) {
+ av_log(s->avctx, AV_LOG_ERROR, "time_incr %d too large\n", time_incr);
+ return AVERROR(EINVAL);
+ }
while (time_incr--)
put_bits(&s->pb, 1, 1);
@@ -1137,6 +1143,8 @@ void ff_mpeg4_encode_picture_header(MpegEncContext *s, int picture_number)
put_bits(&s->pb, 3, s->f_code); /* fcode_for */
if (s->pict_type == AV_PICTURE_TYPE_B)
put_bits(&s->pb, 3, s->b_code); /* fcode_back */
+
+ return 0;
}
static av_cold void init_uni_dc_tab(void)
diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c
index 6b997f121f..2bc7709970 100644
--- a/libavcodec/mpegvideo_enc.c
+++ b/libavcodec/mpegvideo_enc.c
@@ -3714,9 +3714,11 @@ static int encode_picture(MpegEncContext *s, int picture_number)
ff_wmv2_encode_picture_header(s, picture_number);
else if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version)
ff_msmpeg4_encode_picture_header(s, picture_number);
- else if (CONFIG_MPEG4_ENCODER && s->h263_pred)
- ff_mpeg4_encode_picture_header(s, picture_number);
- else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10) {
+ else if (CONFIG_MPEG4_ENCODER && s->h263_pred) {
+ ret = ff_mpeg4_encode_picture_header(s, picture_number);
+ if (ret < 0)
+ return ret;
+ } else if (CONFIG_RV10_ENCODER && s->codec_id == AV_CODEC_ID_RV10) {
ret = ff_rv10_encode_picture_header(s, picture_number);
if (ret < 0)
return ret;