aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorChristophe Gisquet <christophe.gisquet@gmail.com>2014-08-18 14:15:22 +0000
committerLuca Barbato <lu_zero@gentoo.org>2014-08-18 18:51:44 +0200
commit58b68e4fdea22e22178e237bda950b09cc6f363a (patch)
tree3a89765528a3543f7223f07f209d3e112ae26e7a /libavcodec
parentb16699f2da9c1d41eff852ec3a0c81f74fd44421 (diff)
downloadffmpeg-58b68e4fdea22e22178e237bda950b09cc6f363a.tar.gz
proresenc: Report buffer overflow
If the allocated size, despite best efforts, is too small, exit with the appropriate error. CC: libav-stable@libav.org Signed-off-by: Diego Biurrun <diego@biurrun.de> Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/proresenc.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/libavcodec/proresenc.c b/libavcodec/proresenc.c
index 6acaededc5..2ac9792865 100644
--- a/libavcodec/proresenc.c
+++ b/libavcodec/proresenc.c
@@ -566,6 +566,11 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic,
ctx->blocks[0], quant);
}
total_size += sizes[i];
+ if (put_bits_left(pb) < 0) {
+ av_log(avctx, AV_LOG_ERROR,
+ "Underestimated required buffer size.\n");
+ return AVERROR_BUG;
+ }
}
return total_size;
}
@@ -936,9 +941,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
avctx->coded_frame->key_frame = 1;
- pkt_size = ctx->frame_size_upper_bound + FF_MIN_BUFFER_SIZE;
+ pkt_size = ctx->frame_size_upper_bound;
- if ((ret = ff_alloc_packet(pkt, pkt_size)) < 0) {
+ if ((ret = ff_alloc_packet(pkt, pkt_size + FF_MIN_BUFFER_SIZE)) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
return ret;
}
@@ -1017,7 +1022,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
slice_hdr = buf;
buf += slice_hdr_size - 1;
init_put_bits(&pb, buf, (pkt_size - (buf - orig_buf)) * 8);
- encode_slice(avctx, pic, &pb, sizes, x, y, q, mbs_per_slice);
+ ret = encode_slice(avctx, pic, &pb, sizes, x, y, q,
+ mbs_per_slice);
+ if (ret < 0)
+ return ret;
bytestream_put_byte(&slice_hdr, q);
slice_size = slice_hdr_size + sizes[ctx->num_planes - 1];