1 Fix CVE-2014-8158 - unrestricted stack memory use in jpc_qmfb.c
2 From https://bugzilla.redhat.com/show_bug.cgi?id=1179298
4 Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
6 diff -up jasper-1.900.1/src/libjasper/jpc/jpc_qmfb.c.CVE-2014-8158 jasper-1.900.1/src/libjasper/jpc/jpc_qmfb.c
7 --- jasper-1.900.1/src/libjasper/jpc/jpc_qmfb.c.CVE-2014-8158 2015-01-19 17:25:28.730195502 +0100
8 +++ jasper-1.900.1/src/libjasper/jpc/jpc_qmfb.c 2015-01-19 17:27:20.214663127 +0100
9 @@ -306,11 +306,7 @@ void jpc_qmfb_split_row(jpc_fix_t *a, in
12 int bufsize = JPC_CEILDIVPOW2(numcols, 1);
13 -#if !defined(HAVE_VLA)
14 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
16 - jpc_fix_t splitbuf[bufsize];
18 jpc_fix_t *buf = splitbuf;
19 register jpc_fix_t *srcptr;
20 register jpc_fix_t *dstptr;
21 @@ -318,7 +314,6 @@ void jpc_qmfb_split_row(jpc_fix_t *a, in
25 -#if !defined(HAVE_VLA)
27 if (bufsize > QMFB_SPLITBUFSIZE) {
28 if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
29 @@ -326,7 +321,6 @@ void jpc_qmfb_split_row(jpc_fix_t *a, in
36 hstartcol = (numcols + 1 - parity) >> 1;
37 @@ -360,12 +354,10 @@ void jpc_qmfb_split_row(jpc_fix_t *a, in
41 -#if !defined(HAVE_VLA)
42 /* If the split buffer was allocated on the heap, free this memory. */
43 if (buf != splitbuf) {
50 @@ -374,11 +366,7 @@ void jpc_qmfb_split_col(jpc_fix_t *a, in
53 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
54 -#if !defined(HAVE_VLA)
55 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE];
57 - jpc_fix_t splitbuf[bufsize];
59 jpc_fix_t *buf = splitbuf;
60 register jpc_fix_t *srcptr;
61 register jpc_fix_t *dstptr;
62 @@ -386,7 +374,6 @@ void jpc_qmfb_split_col(jpc_fix_t *a, in
66 -#if !defined(HAVE_VLA)
68 if (bufsize > QMFB_SPLITBUFSIZE) {
69 if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
70 @@ -394,7 +381,6 @@ void jpc_qmfb_split_col(jpc_fix_t *a, in
77 hstartcol = (numrows + 1 - parity) >> 1;
78 @@ -428,12 +414,10 @@ void jpc_qmfb_split_col(jpc_fix_t *a, in
82 -#if !defined(HAVE_VLA)
83 /* If the split buffer was allocated on the heap, free this memory. */
84 if (buf != splitbuf) {
91 @@ -442,11 +426,7 @@ void jpc_qmfb_split_colgrp(jpc_fix_t *a,
94 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
95 -#if !defined(HAVE_VLA)
96 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
98 - jpc_fix_t splitbuf[bufsize * JPC_QMFB_COLGRPSIZE];
100 jpc_fix_t *buf = splitbuf;
103 @@ -457,7 +437,6 @@ void jpc_qmfb_split_colgrp(jpc_fix_t *a,
107 -#if !defined(HAVE_VLA)
109 if (bufsize > QMFB_SPLITBUFSIZE) {
110 if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
111 @@ -465,7 +444,6 @@ void jpc_qmfb_split_colgrp(jpc_fix_t *a,
118 hstartcol = (numrows + 1 - parity) >> 1;
119 @@ -517,12 +495,10 @@ void jpc_qmfb_split_colgrp(jpc_fix_t *a,
123 -#if !defined(HAVE_VLA)
124 /* If the split buffer was allocated on the heap, free this memory. */
125 if (buf != splitbuf) {
132 @@ -531,11 +507,7 @@ void jpc_qmfb_split_colres(jpc_fix_t *a,
135 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
136 -#if !defined(HAVE_VLA)
137 jpc_fix_t splitbuf[QMFB_SPLITBUFSIZE * JPC_QMFB_COLGRPSIZE];
139 - jpc_fix_t splitbuf[bufsize * numcols];
141 jpc_fix_t *buf = splitbuf;
144 @@ -546,7 +518,6 @@ void jpc_qmfb_split_colres(jpc_fix_t *a,
148 -#if !defined(HAVE_VLA)
150 if (bufsize > QMFB_SPLITBUFSIZE) {
151 if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
152 @@ -554,7 +525,6 @@ void jpc_qmfb_split_colres(jpc_fix_t *a,
159 hstartcol = (numrows + 1 - parity) >> 1;
160 @@ -606,12 +576,10 @@ void jpc_qmfb_split_colres(jpc_fix_t *a,
164 -#if !defined(HAVE_VLA)
165 /* If the split buffer was allocated on the heap, free this memory. */
166 if (buf != splitbuf) {
173 @@ -619,18 +587,13 @@ void jpc_qmfb_join_row(jpc_fix_t *a, int
176 int bufsize = JPC_CEILDIVPOW2(numcols, 1);
177 -#if !defined(HAVE_VLA)
178 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
180 - jpc_fix_t joinbuf[bufsize];
182 jpc_fix_t *buf = joinbuf;
183 register jpc_fix_t *srcptr;
184 register jpc_fix_t *dstptr;
188 -#if !defined(HAVE_VLA)
189 /* Allocate memory for the join buffer from the heap. */
190 if (bufsize > QMFB_JOINBUFSIZE) {
191 if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
192 @@ -638,7 +601,6 @@ void jpc_qmfb_join_row(jpc_fix_t *a, int
198 hstartcol = (numcols + 1 - parity) >> 1;
200 @@ -670,12 +632,10 @@ void jpc_qmfb_join_row(jpc_fix_t *a, int
204 -#if !defined(HAVE_VLA)
205 /* If the join buffer was allocated on the heap, free this memory. */
206 if (buf != joinbuf) {
213 @@ -684,18 +644,13 @@ void jpc_qmfb_join_col(jpc_fix_t *a, int
216 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
217 -#if !defined(HAVE_VLA)
218 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE];
220 - jpc_fix_t joinbuf[bufsize];
222 jpc_fix_t *buf = joinbuf;
223 register jpc_fix_t *srcptr;
224 register jpc_fix_t *dstptr;
228 -#if !defined(HAVE_VLA)
229 /* Allocate memory for the join buffer from the heap. */
230 if (bufsize > QMFB_JOINBUFSIZE) {
231 if (!(buf = jas_alloc2(bufsize, sizeof(jpc_fix_t)))) {
232 @@ -703,7 +658,6 @@ void jpc_qmfb_join_col(jpc_fix_t *a, int
238 hstartcol = (numrows + 1 - parity) >> 1;
240 @@ -735,12 +689,10 @@ void jpc_qmfb_join_col(jpc_fix_t *a, int
244 -#if !defined(HAVE_VLA)
245 /* If the join buffer was allocated on the heap, free this memory. */
246 if (buf != joinbuf) {
253 @@ -749,11 +701,7 @@ void jpc_qmfb_join_colgrp(jpc_fix_t *a,
256 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
257 -#if !defined(HAVE_VLA)
258 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
260 - jpc_fix_t joinbuf[bufsize * JPC_QMFB_COLGRPSIZE];
262 jpc_fix_t *buf = joinbuf;
265 @@ -763,7 +711,6 @@ void jpc_qmfb_join_colgrp(jpc_fix_t *a,
269 -#if !defined(HAVE_VLA)
270 /* Allocate memory for the join buffer from the heap. */
271 if (bufsize > QMFB_JOINBUFSIZE) {
272 if (!(buf = jas_alloc2(bufsize, JPC_QMFB_COLGRPSIZE * sizeof(jpc_fix_t)))) {
273 @@ -771,7 +718,6 @@ void jpc_qmfb_join_colgrp(jpc_fix_t *a,
279 hstartcol = (numrows + 1 - parity) >> 1;
281 @@ -821,12 +767,10 @@ void jpc_qmfb_join_colgrp(jpc_fix_t *a,
282 srcptr += JPC_QMFB_COLGRPSIZE;
285 -#if !defined(HAVE_VLA)
286 /* If the join buffer was allocated on the heap, free this memory. */
287 if (buf != joinbuf) {
294 @@ -835,11 +779,7 @@ void jpc_qmfb_join_colres(jpc_fix_t *a,
297 int bufsize = JPC_CEILDIVPOW2(numrows, 1);
298 -#if !defined(HAVE_VLA)
299 jpc_fix_t joinbuf[QMFB_JOINBUFSIZE * JPC_QMFB_COLGRPSIZE];
301 - jpc_fix_t joinbuf[bufsize * numcols];
303 jpc_fix_t *buf = joinbuf;
306 @@ -849,7 +789,6 @@ void jpc_qmfb_join_colres(jpc_fix_t *a,
310 -#if !defined(HAVE_VLA)
311 /* Allocate memory for the join buffer from the heap. */
312 if (bufsize > QMFB_JOINBUFSIZE) {
313 if (!(buf = jas_alloc3(bufsize, numcols, sizeof(jpc_fix_t)))) {
314 @@ -857,7 +796,6 @@ void jpc_qmfb_join_colres(jpc_fix_t *a,
320 hstartcol = (numrows + 1 - parity) >> 1;
322 @@ -907,12 +845,10 @@ void jpc_qmfb_join_colres(jpc_fix_t *a,
326 -#if !defined(HAVE_VLA)
327 /* If the join buffer was allocated on the heap, free this memory. */
328 if (buf != joinbuf) {