aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2017-07-16 14:57:20 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2017-07-16 17:02:31 +0200
commit3cae97b090e139acfcda6dda7c73f2e607c4f74a (patch)
treefc41dd0d0d3383f8ca8baab0cea95229dffaab25 /libavcodec
parent654ff561032a252bfa0f31b74ea54dad98dba294 (diff)
downloadffmpeg-3cae97b090e139acfcda6dda7c73f2e607c4f74a.tar.gz
avcodec/apedec: Fix integer overflow
Fixes: out of array access Fixes: PoC.ape and others Found-by: Bingchang, Liu@VARAS of IIE Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit ba4beaf6149f7241c8bd85fe853318c2f6837ad0) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/apedec.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index de9d71ca40..a0ad7dc395 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -1404,6 +1404,7 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
int32_t *sample24;
int i, ch, ret;
int blockstodecode;
+ uint64_t decoded_buffer_size;
/* this should never be negative, but bad things will happen if it is, so
check it just to make sure. */
@@ -1459,7 +1460,7 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
skip_bits_long(&s->gb, offset);
}
- if (!nblocks || nblocks > INT_MAX) {
+ if (!nblocks || nblocks > INT_MAX / 2 / sizeof(*s->decoded_buffer) - 8) {
av_log(avctx, AV_LOG_ERROR, "Invalid sample count: %"PRIu32".\n",
nblocks);
return AVERROR_INVALIDDATA;
@@ -1485,8 +1486,9 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
blockstodecode = s->samples;
/* reallocate decoded sample buffer if needed */
- av_fast_malloc(&s->decoded_buffer, &s->decoded_size,
- 2 * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer));
+ decoded_buffer_size = 2LL * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer);
+ av_assert0(decoded_buffer_size <= INT_MAX);
+ av_fast_malloc(&s->decoded_buffer, &s->decoded_size, decoded_buffer_size);
if (!s->decoded_buffer)
return AVERROR(ENOMEM);
memset(s->decoded_buffer, 0, s->decoded_size);