1From 27354e9d9696ee2bc063910a6c9a6b27c5184a52 Mon Sep 17 00:00:00 2001
2From: Albert Astals Cid <aacid@kde.org>
3Date: Thu, 25 Aug 2022 00:14:22 +0200
4Subject: [PATCH] JBIG2Stream: Fix crash on broken file
5
6https://github.com/jeffssh/CVE-2021-30860
7
8Thanks to David Warren for the heads up
9
10CVE: CVE-2021-30860
11
12References:
13https://nvd.nist.gov/vuln/detail/CVE-2021-30860
14
15Upstream-Status: Backport
16[https://gitlab.freedesktop.org/poppler/poppler/-/commit/27354e9d9696ee2bc063910a6c9a6b27c5184a52]
17
18Signed-off-by: Yogita Urade <yogita.urade@windriver.com>
19---
20 poppler/JBIG2Stream.cc | 6 +++++-
21 1 file changed, 5 insertions(+), 1 deletion(-)
22
23diff --git a/poppler/JBIG2Stream.cc b/poppler/JBIG2Stream.cc
24index 662276e5..9f70431d 100644
25--- a/poppler/JBIG2Stream.cc
26+++ b/poppler/JBIG2Stream.cc
27@@ -1976,7 +1976,11 @@ void JBIG2Stream::readTextRegionSeg(unsigned int segNum, bool imm, bool lossless
28     for (i = 0; i < nRefSegs; ++i) {
29         if ((seg = findSegment(refSegs[i]))) {
30             if (seg->getType() == jbig2SegSymbolDict) {
31-                numSyms += ((JBIG2SymbolDict *)seg)->getSize();
32+                const unsigned int segSize = ((JBIG2SymbolDict *)seg)->getSize();
33+                if (unlikely(checkedAdd(numSyms, segSize, &numSyms))) {
34+                    error(errSyntaxError, getPos(), "Too many symbols in JBIG2 text region");
35+                    return;
36+                }
37             } else if (seg->getType() == jbig2SegCodeTable) {
38                 codeTables.push_back(seg);
39             }
40--
412.25.1
42