aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2015-04-28 11:13:43 +0200
committerMichael Niedermayer <michaelni@gmx.at>2015-05-21 20:43:37 +0200
commitc946f2cc83cf33bd01e8de168e0345a05f68b2ce (patch)
tree20e0a360d32e3cb680b3dc48087d04a4bb838fe6 /libavcodec
parent1e6352578ae4319b2427f9f2ffb8042e8d11894f (diff)
downloadffmpeg-c946f2cc83cf33bd01e8de168e0345a05f68b2ce.tar.gz
apedec: prevent out of array writes in decode_array_0000
s->decoded_buffer is allocated with a min_size of: 2 * FFALIGN(blockstodecode, 8) * sizeof(*s->decoded_buffer) Then it is assigned to s->decoded[0] (and s->decoded_buffer + FFALIGN(blockstodecode, 8) to s->decoded[1]) and passed as out buffer to decode_array_0000. In this function 64 elements of the out buffer are written unconditionally and outside the array if blockstodecode is too small. This causes memory corruption, leading to segmentation faults or other crashes. Thus change decode_array_0000 to write at most blockstodecode elements of the out buffer. Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit 699341d647f7af785fb8ceed67604467b0b9ab12) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/apedec.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c
index 2ccbdc8005..577d0aa260 100644
--- a/libavcodec/apedec.c
+++ b/libavcodec/apedec.c
@@ -601,14 +601,14 @@ static void decode_array_0000(APEContext *ctx, GetBitContext *gb,
int ksummax, ksummin;
rice->ksum = 0;
- for (i = 0; i < 5; i++) {
+ for (i = 0; i < FFMIN(blockstodecode, 5); i++) {
out[i] = get_rice_ook(&ctx->gb, 10);
rice->ksum += out[i];
}
rice->k = av_log2(rice->ksum / 10) + 1;
if (rice->k >= 24)
return;
- for (; i < 64; i++) {
+ for (; i < FFMIN(blockstodecode, 64); i++) {
out[i] = get_rice_ook(&ctx->gb, rice->k);
rice->ksum += out[i];
rice->k = av_log2(rice->ksum / ((i + 1) * 2)) + 1;