From 39bec05ed42e505d17877b0c23f16322f9b5883b Mon Sep 17 00:00:00 2001
From: Michael Niedermayer <michaelni@gmx.at>
Date: Fri, 30 Nov 2012 23:59:40 +0100
Subject: [PATCH] qdm2: check array index before use, fix out of array accesses

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>

(cherry picked from commit a7ee6281f7ef1c29284e3a4cadfe0f227ffde1ed)

CC: libav-stable@libav.org

Signed-off-by: Reinhard Tartler <siretart@tauware.de>
---
 libavcodec/qdm2.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c
index 1286cc51638..61ac0a830df 100644
--- a/libavcodec/qdm2.c
+++ b/libavcodec/qdm2.c
@@ -1232,6 +1232,11 @@ static void qdm2_decode_super_block (QDM2Context *q)
     for (i = 0; packet_bytes > 0; i++) {
         int j;
 
+        if (i >= FF_ARRAY_ELEMS(q->sub_packet_list_A)) {
+            SAMPLES_NEEDED_2("too many packet bytes");
+            return;
+        }
+
         q->sub_packet_list_A[i].next = NULL;
 
         if (i > 0) {
-- 
GitLab