aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/qdm2.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-11-18 17:48:31 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-11-21 22:01:29 +0100
commit4b0f8aed13efc53b62b5fb2eabdc55cd4c0967ae (patch)
treedb8ad9fc315aab043b63c98ad1a6a574e66cc144 /libavcodec/qdm2.c
parent2c8ac664561a1843f299295443720ce83105c024 (diff)
downloadffmpeg-4b0f8aed13efc53b62b5fb2eabdc55cd4c0967ae.tar.gz
qdm2dec: fix buffer overflow.
Fixes NGS00144 This also adds a few lines of code from master that are needed for this fix. Thanks to Phillip for suggestions to improve the patch. Found-by: Phillip Langlois Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit a6a61a6d1d4da219a6fe29250e2a6b28f9d05524) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/qdm2.c')
-rw-r--r--libavcodec/qdm2.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 3aef7a36e2..f9fed4f71c 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -77,6 +77,7 @@ do { \
#define SAMPLES_NEEDED_2(why) \
av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why);
+#define QDM2_MAX_FRAME_SIZE 512
typedef int8_t sb_int8_array[2][30][64];
@@ -169,7 +170,7 @@ typedef struct {
/// I/O data
const uint8_t *compressed_data;
int compressed_size;
- float output_buffer[1024];
+ float output_buffer[QDM2_MAX_FRAME_SIZE * MPA_MAX_CHANNELS * 2];
/// Synthesis filter
DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512*2]);
@@ -1845,7 +1846,8 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
// something like max decodable tones
s->group_order = av_log2(s->group_size) + 1;
s->frame_size = s->group_size / 16; // 16 iterations per super block
- if (s->frame_size > FF_ARRAY_ELEMS(s->output_buffer) / 2)
+
+ if (s->frame_size > QDM2_MAX_FRAME_SIZE)
return AVERROR_INVALIDDATA;
s->sub_sampling = s->fft_order - 7;
@@ -1915,6 +1917,9 @@ static void qdm2_decode (QDM2Context *q, const uint8_t *in, int16_t *out)
int ch, i;
const int frame_size = (q->frame_size * q->channels);
+ if((unsigned)frame_size > FF_ARRAY_ELEMS(q->output_buffer)/2)
+ return -1;
+
/* select input buffer */
q->compressed_data = in;
q->compressed_size = q->checksum_size;