summaryrefslogtreecommitdiff
path: root/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp')
-rw-r--r--chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp236
1 files changed, 212 insertions, 24 deletions
diff --git a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp
index 8c6d58e5119..675de9bcddf 100644
--- a/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp
+++ b/chromium/third_party/pdfium/core/fxcodec/jbig2/JBig2_GrdProc.cpp
@@ -12,6 +12,7 @@
#include "core/fxcodec/jbig2/JBig2_ArithDecoder.h"
#include "core/fxcodec/jbig2/JBig2_BitStream.h"
#include "core/fxcodec/jbig2/JBig2_Image.h"
+#include "third_party/base/ptr_util.h"
CJBig2_GRDProc::CJBig2_GRDProc()
: m_loopIndex(0),
@@ -65,7 +66,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith(CJBig2_ArithDecoder* pArithDecoder,
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -77,8 +78,12 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
int32_t nBitsLeft = GBW - (nLineBytes << 3);
uint32_t height = GBH & 0x7fffffff;
for (uint32_t h = 0; h < height; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]);
+ }
if (LTP) {
GBREG->copyLine(h, h - 1);
} else {
@@ -93,6 +98,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
line2 = (line2 << 8) | (*pLine2++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
@@ -104,6 +112,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
@@ -121,6 +132,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
}
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT =
@@ -131,6 +145,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
@@ -148,11 +165,15 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]);
+ }
if (LTP) {
GBREG->copyLine(h, h - 1);
} else {
@@ -174,6 +195,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt(
CONTEXT |= GBREG->getPixel(w + GBAT[4], h + GBAT[5]) << 11;
CONTEXT |= line1 << 12;
CONTEXT |= GBREG->getPixel(w + GBAT[6], h + GBAT[7]) << 15;
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {
@@ -191,7 +215,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template0_unopt(
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -202,8 +226,12 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]);
+ }
if (LTP) {
GBREG->copyLine(h, h - 1);
} else {
@@ -218,6 +246,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
line2 = (line2 << 8) | (*pLine2++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
@@ -229,6 +260,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
@@ -246,6 +280,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
}
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
@@ -256,6 +293,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
@@ -273,11 +313,15 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]);
+ }
if (LTP) {
GBREG->copyLine(h, h - 1);
} else {
@@ -297,6 +341,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt(
CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 3;
CONTEXT |= line2 << 4;
CONTEXT |= line1 << 9;
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {
@@ -314,7 +361,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template1_unopt(
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -325,8 +372,12 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]);
+ }
if (LTP) {
GBREG->copyLine(h, h - 1);
} else {
@@ -341,6 +392,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
line2 = (line2 << 8) | (*pLine2++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -352,6 +406,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -369,6 +426,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
}
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -379,6 +439,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -396,11 +459,15 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]);
+ }
if (LTP) {
GBREG->copyLine(h, h - 1);
} else {
@@ -418,6 +485,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt(
CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 2;
CONTEXT |= line2 << 3;
CONTEXT |= line1 << 7;
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {
@@ -435,7 +505,7 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template2_unopt(
CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
if (!GBREG->m_pData)
return nullptr;
@@ -444,9 +514,15 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
int32_t nStride = GBREG->stride();
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
+
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]);
+ }
+
if (LTP) {
GBREG->copyLine(h, h - 1);
} else {
@@ -458,6 +534,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
line1 = (line1 << 8) | (*pLine1++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
@@ -468,6 +547,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
line1 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
@@ -479,6 +561,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
for (int32_t cc = 0; cc < nLineBytes; cc++) {
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
@@ -487,6 +572,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_opt3(
}
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
@@ -503,11 +591,15 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt(
CJBig2_ArithDecoder* pArithDecoder,
JBig2ArithCtx* gbContext) {
int LTP = 0;
- std::unique_ptr<CJBig2_Image> GBREG(new CJBig2_Image(GBW, GBH));
+ auto GBREG = pdfium::MakeUnique<CJBig2_Image>(GBW, GBH);
GBREG->fill(0);
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
LTP = LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]);
+ }
if (LTP == 1) {
GBREG->copyLine(h, h - 1);
} else {
@@ -522,6 +614,9 @@ CJBig2_Image* CJBig2_GRDProc::decode_Arith_Template3_unopt(
uint32_t CONTEXT = line2;
CONTEXT |= GBREG->getPixel(w + GBAT[0], h + GBAT[1]) << 4;
CONTEXT |= line1 << 5;
+ if (pArithDecoder->IsComplete())
+ return nullptr;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {
@@ -658,9 +753,14 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3(
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
uint32_t height = GBH & 0x7fffffff;
+
for (; m_loopIndex < height; m_loopIndex++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]);
+ }
if (m_LTP) {
pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
@@ -675,6 +775,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3(
line2 = (line2 << 8) | (*pLine2++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
@@ -686,6 +789,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
@@ -703,6 +809,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3(
}
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT =
@@ -713,6 +822,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = (((CONTEXT & 0x7bf7) << 1) | bVal |
@@ -738,8 +850,12 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_unopt(
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
for (; m_loopIndex < GBH; m_loopIndex++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x9b25]);
+ }
if (m_LTP) {
pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
@@ -761,6 +877,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template0_unopt(
CONTEXT |= pImage->getPixel(w + GBAT[4], m_loopIndex + GBAT[5]) << 11;
CONTEXT |= line1 << 12;
CONTEXT |= pImage->getPixel(w + GBAT[6], m_loopIndex + GBAT[7]) << 15;
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {
@@ -796,8 +915,12 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3(
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
for (; m_loopIndex < GBH; m_loopIndex++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]);
+ }
if (m_LTP) {
pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
@@ -812,6 +935,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3(
line2 = (line2 << 8) | (*pLine2++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
@@ -823,6 +949,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
@@ -840,6 +969,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3(
}
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x0efb) << 1) | bVal |
@@ -850,6 +982,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
@@ -875,8 +1010,12 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_unopt(
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
for (uint32_t h = 0; h < GBH; h++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0795]);
+ }
if (m_LTP) {
pImage->copyLine(h, h - 1);
} else {
@@ -896,6 +1035,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template1_unopt(
CONTEXT |= pImage->getPixel(w + GBAT[0], h + GBAT[1]) << 3;
CONTEXT |= line2 << 4;
CONTEXT |= line1 << 9;
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {
@@ -929,8 +1071,12 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3(
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
for (; m_loopIndex < GBH; m_loopIndex++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]);
+ }
if (m_LTP) {
pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
@@ -945,6 +1091,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3(
line2 = (line2 << 8) | (*pLine2++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -956,6 +1105,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -973,6 +1125,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3(
}
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -983,6 +1138,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_opt3(
line2 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01bd) << 1) | bVal |
@@ -1008,8 +1166,12 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_unopt(
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
for (; m_loopIndex < GBH; m_loopIndex++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x00e5]);
+ }
if (m_LTP) {
pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
@@ -1027,6 +1189,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template2_unopt(
CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 2;
CONTEXT |= line2 << 3;
CONTEXT |= line1 << 7;
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {
@@ -1061,8 +1226,12 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3(
int32_t nLineBytes = ((GBW + 7) >> 3) - 1;
int32_t nBitsLeft = GBW - (nLineBytes << 3);
for (; m_loopIndex < GBH; m_loopIndex++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]);
+ }
if (m_LTP) {
pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
@@ -1074,6 +1243,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3(
line1 = (line1 << 8) | (*pLine1++);
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal |
@@ -1084,6 +1256,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3(
line1 <<= 8;
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT =
@@ -1095,6 +1270,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3(
for (int32_t cc = 0; cc < nLineBytes; cc++) {
uint8_t cVal = 0;
for (int32_t k = 7; k >= 0; k--) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal |= bVal << k;
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
@@ -1103,6 +1281,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_opt3(
}
uint8_t cVal1 = 0;
for (int32_t k = 0; k < nBitsLeft; k++) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
int bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
cVal1 |= bVal << (7 - k);
CONTEXT = ((CONTEXT & 0x01f7) << 1) | bVal;
@@ -1127,8 +1308,12 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_unopt(
JBig2ArithCtx* gbContext,
IFX_Pause* pPause) {
for (; m_loopIndex < GBH; m_loopIndex++) {
- if (TPGDON)
+ if (TPGDON) {
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
m_LTP = m_LTP ^ pArithDecoder->DECODE(&gbContext[0x0195]);
+ }
if (m_LTP) {
pImage->copyLine(m_loopIndex, m_loopIndex - 1);
} else {
@@ -1143,6 +1328,9 @@ FXCODEC_STATUS CJBig2_GRDProc::decode_Arith_Template3_unopt(
uint32_t CONTEXT = line2;
CONTEXT |= pImage->getPixel(w + GBAT[0], m_loopIndex + GBAT[1]) << 4;
CONTEXT |= line1 << 5;
+ if (pArithDecoder->IsComplete())
+ return FXCODEC_STATUS_ERROR;
+
bVal = pArithDecoder->DECODE(&gbContext[CONTEXT]);
}
if (bVal) {