aboutsummaryrefslogtreecommitdiffstats
path: root/main/openjpeg/CVE-2018-14423.patch
blob: 81fcb59345966dad210976a912751bd7010a3f34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
From bd88611ed9ad7144ec4f3de54790cd848175891b Mon Sep 17 00:00:00 2001
From: Young_X <YangX92@hotmail.com>
Date: Fri, 23 Nov 2018 17:15:05 +0800
Subject: [PATCH]  [JP3D] To avoid divisions by zero / undefined behaviour on
 shift (CVE-2018-14423

Signed-off-by: Young_X <YangX92@hotmail.com>
---
 src/lib/openjp3d/pi.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/src/lib/openjp3d/pi.c b/src/lib/openjp3d/pi.c
index a03be45e7..a58ebcc7c 100644
--- a/src/lib/openjp3d/pi.c
+++ b/src/lib/openjp3d/pi.c
@@ -223,6 +223,14 @@ static bool pi_next_rpcl(opj_pi_iterator_t * pi)
                         rpx = res->pdx + levelnox;
                         rpy = res->pdy + levelnoy;
                         rpz = res->pdz + levelnoz;
+
+                        /* To avoid divisions by zero / undefined behaviour on shift */
+                        if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
+                                rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy ||
+                                rpz >= 31 || ((comp->dz << rpz) >> rpz) != comp->dz) {
+                            continue;
+                        }
+
                         if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 &&
                                 (trx0 << levelnox) % (1 << rpx)))) {
                             continue;
@@ -329,6 +337,14 @@ static bool pi_next_pcrl(opj_pi_iterator_t * pi)
                         rpx = res->pdx + levelnox;
                         rpy = res->pdy + levelnoy;
                         rpz = res->pdz + levelnoz;
+
+                        /* To avoid divisions by zero / undefined behaviour on shift */
+                        if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
+                                rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy ||
+                                rpz >= 31 || ((comp->dz << rpz) >> rpz) != comp->dz) {
+                            continue;
+                        }
+
                         if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 &&
                                 (trx0 << levelnox) % (1 << rpx)))) {
                             continue;
@@ -432,6 +448,14 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi)
                         rpx = res->pdx + levelnox;
                         rpy = res->pdy + levelnoy;
                         rpz = res->pdz + levelnoz;
+
+                        /* To avoid divisions by zero / undefined behaviour on shift */
+                        if (rpx >= 31 || ((comp->dx << rpx) >> rpx) != comp->dx ||
+                                rpy >= 31 || ((comp->dy << rpy) >> rpy) != comp->dy ||
+                                rpz >= 31 || ((comp->dz << rpz) >> rpz) != comp->dz) {
+                            continue;
+                        }
+
                         if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 &&
                                 (trx0 << levelnox) % (1 << rpx)))) {
                             continue;