av_realloc() does not guarantee alignment, which is required for
DSPContext.bswap_buf().
---
libavcodec/fraps.c | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/libavcodec/fraps.c b/libavcodec/fraps.c
index 1444eda..fa89fde 100644
--- a/libavcodec/fraps.c
+++ b/libavcodec/fraps.c
@@ -46,6 +46,7 @@ typedef struct FrapsContext{
AVCodecContext *avctx;
AVFrame frame;
uint8_t *tmpbuf;
+ int tmpbuf_size;
DSPContext dsp;
} FrapsContext;
@@ -275,8 +276,15 @@ static int decode_frame(AVCodecContext *avctx,
}
offs[planes] = buf_size;
for(i = 0; i < planes; i++){
+ int new_size = offs[i + 1] - offs[i] - 1024 +
FF_INPUT_BUFFER_PADDING_SIZE;
is_chroma = !!i;
- s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 +
FF_INPUT_BUFFER_PADDING_SIZE);
+ if (s->tmpbuf_size < new_size) {
+ av_freep(&s->tmpbuf);
+ if (!(s->tmpbuf = av_mallocz(new_size))) {
+ s->tmpbuf_size = 0;
+ return AVERROR(ENOMEM);
+ }
+ }
if(fraps2_decode_plane(s, f->data[i], f->linesize[i], avctx->width
>> is_chroma,
avctx->height >> is_chroma, buf + offs[i], offs[i + 1] -
offs[i], is_chroma, 1) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i);
@@ -318,7 +326,14 @@ static int decode_frame(AVCodecContext *avctx,
}
offs[planes] = buf_size;
for(i = 0; i < planes; i++){
- s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 +
FF_INPUT_BUFFER_PADDING_SIZE);
+ int new_size = offs[i + 1] - offs[i] - 1024 +
FF_INPUT_BUFFER_PADDING_SIZE;
+ if (s->tmpbuf_size < new_size) {
+ av_freep(&s->tmpbuf);
+ if (!(s->tmpbuf = av_mallocz(new_size))) {
+ s->tmpbuf_size = 0;
+ return AVERROR(ENOMEM);
+ }
+ }
if(fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] *
(avctx->height - 1)), -f->linesize[0],
avctx->width, avctx->height, buf + offs[i], offs[i + 1] -
offs[i], 0, 3) < 0) {
av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i);
@@ -355,6 +370,8 @@ static av_cold int decode_end(AVCodecContext *avctx)
avctx->release_buffer(avctx, &s->frame);
av_freep(&s->tmpbuf);
+ s->tmpbuf_size = 0;
+
return 0;
}
--
1.7.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel