diff options
author | Justin Ruggles <justin.ruggles@gmail.com> | 2011-09-15 18:08:52 -0400 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2013-02-10 18:01:15 +0100 |
commit | 7aeb281aa5078726eef5f7db0e7b513932454dc0 (patch) | |
tree | c14d99b1439eec32de8779448a81a9505753f529 /libavcodec | |
parent | a49599b1255ec0300cdec1591edf506433407804 (diff) | |
download | ffmpeg-7aeb281aa5078726eef5f7db0e7b513932454dc0.tar.gz |
shorten: check for realloc failure
(cherry picked from commit 9e5e2c2d010c05c10337e9c1ec9d0d61495e0c9c)
Conflicts:
libavcodec/shorten.c
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/shorten.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/libavcodec/shorten.c b/libavcodec/shorten.c index 053f5c2ed1..9d66d76b4f 100644 --- a/libavcodec/shorten.c +++ b/libavcodec/shorten.c @@ -112,6 +112,8 @@ static av_cold int shorten_decode_init(AVCodecContext * avctx) static int allocate_buffers(ShortenContext *s) { int i, chan; + void *tmp_ptr; + for (chan=0; chan<s->channels; chan++) { if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){ av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n"); @@ -122,9 +124,15 @@ static int allocate_buffers(ShortenContext *s) return -1; } - s->offset[chan] = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); + tmp_ptr = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); + if (!tmp_ptr) + return AVERROR(ENOMEM); + s->offset[chan] = tmp_ptr; - s->decoded[chan] = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap)); + tmp_ptr = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap)); + if (!tmp_ptr) + return AVERROR(ENOMEM); + s->decoded[chan] = tmp_ptr; for (i=0; i<s->nwrap; i++) s->decoded[chan][i] = 0; s->decoded[chan] += s->nwrap; @@ -275,8 +283,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, int i, input_buf_size = 0; int16_t *samples = data; if(s->max_framesize == 0){ + void *tmp_ptr; s->max_framesize= 1024; // should hopefully be enough for the first header - s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); + tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, + s->max_framesize); + if (!tmp_ptr) { + av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n"); + return AVERROR(ENOMEM); + } + s->bitstream = tmp_ptr; } if(1 && s->max_framesize){//FIXME truncated |