summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-08-22 17:34:42 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-22 17:34:42 +0000
commitdc7e7fa32798770243289827c9db2607061fb2a7 (patch)
tree49b072a5cde02f73186f83a3bc6c669506dcdec1 /core
parent962c1bc7e550b9466d802b0b94322693611fa30b (diff)
downloadpdfium-dc7e7fa32798770243289827c9db2607061fb2a7.tar.xz
Use UnownedPtr<> in JBig2_TrdProc, part 2.
Re-order some locals to obey strict lifetime constraint. Pack a little tighter. Change-Id: Iae011d21b934fac865cf10ac20c046c8917d3a98 Reviewed-on: https://pdfium-review.googlesource.com/40915 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core')
-rw-r--r--core/fxcodec/jbig2/JBig2_SddProc.cpp34
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.cpp19
-rw-r--r--core/fxcodec/jbig2/JBig2_TrdProc.h30
3 files changed, 41 insertions, 42 deletions
diff --git a/core/fxcodec/jbig2/JBig2_SddProc.cpp b/core/fxcodec/jbig2/JBig2_SddProc.cpp
index 7bdcf5c5f9..0d2ce14de2 100644
--- a/core/fxcodec/jbig2/JBig2_SddProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_SddProc.cpp
@@ -120,6 +120,15 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeArith(
} else {
IAAI->Decode(pArithDecoder, (int*)&REFAGGNINST);
if (REFAGGNINST > 1) {
+ // Huffman tables must not outlive |pDecoder|.
+ auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(6);
+ auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(8);
+ auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(11);
+ auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
auto pDecoder = pdfium::MakeUnique<CJBig2_TRDProc>();
pDecoder->SBHUFF = SDHUFF;
pDecoder->SBREFINE = 1;
@@ -145,14 +154,6 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeArith(
pDecoder->TRANSPOSED = 0;
pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT;
pDecoder->SBDSOFFSET = 0;
- auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(6);
- auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(8);
- auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(11);
- auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
pDecoder->SBHUFFFS = SBHUFFFS.get();
pDecoder->SBHUFFDS = SBHUFFDS.get();
pDecoder->SBHUFFDT = SBHUFFDT.get();
@@ -329,6 +330,15 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeHuffman(
}
BS = nullptr;
if (REFAGGNINST > 1) {
+ // Huffman tables must outlive |pDecoder|.
+ auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(6);
+ auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(8);
+ auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(11);
+ auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
+ auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
auto pDecoder = pdfium::MakeUnique<CJBig2_TRDProc>();
pDecoder->SBHUFF = SDHUFF;
pDecoder->SBREFINE = 1;
@@ -357,14 +367,6 @@ std::unique_ptr<CJBig2_SymbolDict> CJBig2_SDDProc::DecodeHuffman(
pDecoder->TRANSPOSED = 0;
pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT;
pDecoder->SBDSOFFSET = 0;
- auto SBHUFFFS = pdfium::MakeUnique<CJBig2_HuffmanTable>(6);
- auto SBHUFFDS = pdfium::MakeUnique<CJBig2_HuffmanTable>(8);
- auto SBHUFFDT = pdfium::MakeUnique<CJBig2_HuffmanTable>(11);
- auto SBHUFFRDW = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRDH = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRDX = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRDY = pdfium::MakeUnique<CJBig2_HuffmanTable>(15);
- auto SBHUFFRSIZE = pdfium::MakeUnique<CJBig2_HuffmanTable>(1);
pDecoder->SBHUFFFS = SBHUFFFS.get();
pDecoder->SBHUFFDS = SBHUFFDS.get();
pDecoder->SBHUFFDT = SBHUFFDT.get();
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.cpp b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
index 4f082f376f..7aa5989972 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.cpp
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.cpp
@@ -57,7 +57,7 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeHuffman(
SBREG->Fill(SBDEFPIXEL);
int32_t INITIAL_STRIPT;
auto pHuffmanDecoder = pdfium::MakeUnique<CJBig2_HuffmanDecoder>(pStream);
- if (pHuffmanDecoder->DecodeAValue(SBHUFFDT, &INITIAL_STRIPT) != 0)
+ if (pHuffmanDecoder->DecodeAValue(SBHUFFDT.Get(), &INITIAL_STRIPT) != 0)
return nullptr;
FX_SAFE_INT32 STRIPT = INITIAL_STRIPT;
@@ -67,7 +67,7 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeHuffman(
uint32_t NINSTANCES = 0;
while (NINSTANCES < SBNUMINSTANCES) {
int32_t INITIAL_DT;
- if (pHuffmanDecoder->DecodeAValue(SBHUFFDT, &INITIAL_DT) != 0)
+ if (pHuffmanDecoder->DecodeAValue(SBHUFFDT.Get(), &INITIAL_DT) != 0)
return nullptr;
FX_SAFE_INT32 DT = INITIAL_DT;
@@ -78,7 +78,7 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeHuffman(
for (;;) {
if (bFirst) {
int32_t DFS;
- if (pHuffmanDecoder->DecodeAValue(SBHUFFFS, &DFS) != 0)
+ if (pHuffmanDecoder->DecodeAValue(SBHUFFFS.Get(), &DFS) != 0)
return nullptr;
FIRSTS += DFS;
@@ -86,7 +86,7 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeHuffman(
bFirst = false;
} else {
int32_t IDS;
- int32_t nVal = pHuffmanDecoder->DecodeAValue(SBHUFFDS, &IDS);
+ int32_t nVal = pHuffmanDecoder->DecodeAValue(SBHUFFDS.Get(), &IDS);
if (nVal == JBIG2_OOB)
break;
@@ -147,11 +147,12 @@ std::unique_ptr<CJBig2_Image> CJBig2_TRDProc::DecodeHuffman(
int32_t RDXI;
int32_t RDYI;
int32_t HUFFRSIZE;
- if ((pHuffmanDecoder->DecodeAValue(SBHUFFRDW, &RDWI) != 0) ||
- (pHuffmanDecoder->DecodeAValue(SBHUFFRDH, &RDHI) != 0) ||
- (pHuffmanDecoder->DecodeAValue(SBHUFFRDX, &RDXI) != 0) ||
- (pHuffmanDecoder->DecodeAValue(SBHUFFRDY, &RDYI) != 0) ||
- (pHuffmanDecoder->DecodeAValue(SBHUFFRSIZE, &HUFFRSIZE) != 0)) {
+ if ((pHuffmanDecoder->DecodeAValue(SBHUFFRDW.Get(), &RDWI) != 0) ||
+ (pHuffmanDecoder->DecodeAValue(SBHUFFRDH.Get(), &RDHI) != 0) ||
+ (pHuffmanDecoder->DecodeAValue(SBHUFFRDX.Get(), &RDXI) != 0) ||
+ (pHuffmanDecoder->DecodeAValue(SBHUFFRDY.Get(), &RDYI) != 0) ||
+ (pHuffmanDecoder->DecodeAValue(SBHUFFRSIZE.Get(), &HUFFRSIZE) !=
+ 0)) {
return nullptr;
}
pStream->alignByte();
diff --git a/core/fxcodec/jbig2/JBig2_TrdProc.h b/core/fxcodec/jbig2/JBig2_TrdProc.h
index 52c5322ec4..855a13accb 100644
--- a/core/fxcodec/jbig2/JBig2_TrdProc.h
+++ b/core/fxcodec/jbig2/JBig2_TrdProc.h
@@ -59,32 +59,28 @@ class CJBig2_TRDProc {
bool SBHUFF;
bool SBREFINE;
+ bool SBRTEMPLATE;
+ bool TRANSPOSED;
+ bool SBDEFPIXEL;
+ int8_t SBDSOFFSET;
+ uint8_t SBSYMCODELEN;
uint32_t SBW;
uint32_t SBH;
uint32_t SBNUMINSTANCES;
uint32_t SBSTRIPS;
uint32_t SBNUMSYMS;
-
std::vector<JBig2HuffmanCode> SBSYMCODES;
- uint8_t SBSYMCODELEN;
-
CJBig2_Image** SBSYMS;
- bool SBDEFPIXEL;
-
JBig2ComposeOp SBCOMBOP;
- bool TRANSPOSED;
-
JBig2Corner REFCORNER;
- int8_t SBDSOFFSET;
- const CJBig2_HuffmanTable* SBHUFFFS;
- const CJBig2_HuffmanTable* SBHUFFDS;
- const CJBig2_HuffmanTable* SBHUFFDT;
- const CJBig2_HuffmanTable* SBHUFFRDW;
- const CJBig2_HuffmanTable* SBHUFFRDH;
- const CJBig2_HuffmanTable* SBHUFFRDX;
- const CJBig2_HuffmanTable* SBHUFFRDY;
- const CJBig2_HuffmanTable* SBHUFFRSIZE;
- bool SBRTEMPLATE;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFFS;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFDS;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFDT;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDW;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDH;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDX;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRDY;
+ UnownedPtr<const CJBig2_HuffmanTable> SBHUFFRSIZE;
int8_t SBRAT[4];
private: