From dc7e7fa32798770243289827c9db2607061fb2a7 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 22 Aug 2018 17:34:42 +0000 Subject: 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 Commit-Queue: Tom Sepez --- core/fxcodec/jbig2/JBig2_SddProc.cpp | 34 ++++++++++++++++++---------------- core/fxcodec/jbig2/JBig2_TrdProc.cpp | 19 ++++++++++--------- core/fxcodec/jbig2/JBig2_TrdProc.h | 30 +++++++++++++----------------- 3 files changed, 41 insertions(+), 42 deletions(-) (limited to 'core/fxcodec') 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_SDDProc::DecodeArith( } else { IAAI->Decode(pArithDecoder, (int*)&REFAGGNINST); if (REFAGGNINST > 1) { + // Huffman tables must not outlive |pDecoder|. + auto SBHUFFFS = pdfium::MakeUnique(6); + auto SBHUFFDS = pdfium::MakeUnique(8); + auto SBHUFFDT = pdfium::MakeUnique(11); + auto SBHUFFRDW = pdfium::MakeUnique(15); + auto SBHUFFRDH = pdfium::MakeUnique(15); + auto SBHUFFRDX = pdfium::MakeUnique(15); + auto SBHUFFRDY = pdfium::MakeUnique(15); + auto SBHUFFRSIZE = pdfium::MakeUnique(1); auto pDecoder = pdfium::MakeUnique(); pDecoder->SBHUFF = SDHUFF; pDecoder->SBREFINE = 1; @@ -145,14 +154,6 @@ std::unique_ptr CJBig2_SDDProc::DecodeArith( pDecoder->TRANSPOSED = 0; pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT; pDecoder->SBDSOFFSET = 0; - auto SBHUFFFS = pdfium::MakeUnique(6); - auto SBHUFFDS = pdfium::MakeUnique(8); - auto SBHUFFDT = pdfium::MakeUnique(11); - auto SBHUFFRDW = pdfium::MakeUnique(15); - auto SBHUFFRDH = pdfium::MakeUnique(15); - auto SBHUFFRDX = pdfium::MakeUnique(15); - auto SBHUFFRDY = pdfium::MakeUnique(15); - auto SBHUFFRSIZE = pdfium::MakeUnique(1); pDecoder->SBHUFFFS = SBHUFFFS.get(); pDecoder->SBHUFFDS = SBHUFFDS.get(); pDecoder->SBHUFFDT = SBHUFFDT.get(); @@ -329,6 +330,15 @@ std::unique_ptr CJBig2_SDDProc::DecodeHuffman( } BS = nullptr; if (REFAGGNINST > 1) { + // Huffman tables must outlive |pDecoder|. + auto SBHUFFFS = pdfium::MakeUnique(6); + auto SBHUFFDS = pdfium::MakeUnique(8); + auto SBHUFFDT = pdfium::MakeUnique(11); + auto SBHUFFRDW = pdfium::MakeUnique(15); + auto SBHUFFRDH = pdfium::MakeUnique(15); + auto SBHUFFRDX = pdfium::MakeUnique(15); + auto SBHUFFRDY = pdfium::MakeUnique(15); + auto SBHUFFRSIZE = pdfium::MakeUnique(1); auto pDecoder = pdfium::MakeUnique(); pDecoder->SBHUFF = SDHUFF; pDecoder->SBREFINE = 1; @@ -357,14 +367,6 @@ std::unique_ptr CJBig2_SDDProc::DecodeHuffman( pDecoder->TRANSPOSED = 0; pDecoder->REFCORNER = JBIG2_CORNER_TOPLEFT; pDecoder->SBDSOFFSET = 0; - auto SBHUFFFS = pdfium::MakeUnique(6); - auto SBHUFFDS = pdfium::MakeUnique(8); - auto SBHUFFDT = pdfium::MakeUnique(11); - auto SBHUFFRDW = pdfium::MakeUnique(15); - auto SBHUFFRDH = pdfium::MakeUnique(15); - auto SBHUFFRDX = pdfium::MakeUnique(15); - auto SBHUFFRDY = pdfium::MakeUnique(15); - auto SBHUFFRSIZE = pdfium::MakeUnique(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_TRDProc::DecodeHuffman( SBREG->Fill(SBDEFPIXEL); int32_t INITIAL_STRIPT; auto pHuffmanDecoder = pdfium::MakeUnique(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_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_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_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_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 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 SBHUFFFS; + UnownedPtr SBHUFFDS; + UnownedPtr SBHUFFDT; + UnownedPtr SBHUFFRDW; + UnownedPtr SBHUFFRDH; + UnownedPtr SBHUFFRDX; + UnownedPtr SBHUFFRDY; + UnownedPtr SBHUFFRSIZE; int8_t SBRAT[4]; private: -- cgit v1.2.3