From 1c06e11ab7b029246518ca4728000d1f681c03aa Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Thu, 7 Jun 2018 23:59:12 +0000 Subject: Reland "Reland "Simplify CPDF_HintsTable."" This is a reland of d89f1bf48f017ab9f56df13299f75a906ed33cd0 Original change's description: > Reland "Simplify CPDF_HintsTable." > > This is a reland of 33591752d2cb14f2e07726ca52afce6efbdc07c9 > > Original change's description: > > Simplify CPDF_HintsTable. > > > > Use CPDF_LinearizedHeader directly. > > > > Change-Id: Id12402ef6e6f92fef68d0932df2e1ccb2dcf06aa > > Reviewed-on: https://pdfium-review.googlesource.com/15770 > > Reviewed-by: Lei Zhang > > Commit-Queue: Lei Zhang > > Change-Id: I2b5425a6533f4ce237f9ae6c483caa517105a5f7 > Reviewed-on: https://pdfium-review.googlesource.com/34130 > Reviewed-by: Lei Zhang > Commit-Queue: Art Snake Change-Id: If34c4ea05db7c9abaf2ba75ebe1abaabb962dd88 Reviewed-on: https://pdfium-review.googlesource.com/34410 Reviewed-by: Ryan Harrison Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_hint_tables.cpp | 91 +++++++------------------------- core/fpdfapi/parser/cpdf_hint_tables.h | 8 --- 2 files changed, 19 insertions(+), 80 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_hint_tables.cpp b/core/fpdfapi/parser/cpdf_hint_tables.cpp index 9cd72c7815..65beda7e2a 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/parser/cpdf_hint_tables.cpp @@ -62,15 +62,8 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { if (!hStream || hStream->IsEOF()) return false; - int nStreamOffset = ReadPrimaryHintStreamOffset(); - if (nStreamOffset < 0) - return false; - - int nStreamLen = ReadPrimaryHintStreamLength(); - if (nStreamLen < 1 || - !pdfium::base::IsValueInRangeForNumericType(nStreamLen)) { - return false; - } + const FX_FILESIZE nStreamOffset = m_pLinearized->GetHintStart(); + const uint32_t nStreamLen = m_pLinearized->GetHintLength(); const uint32_t kHeaderSize = 288; if (hStream->BitsRemaining() < kHeaderSize) @@ -138,7 +131,7 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { // Item 13: Skip Item 13 which has 16 bits. hStream->SkipBits(16); - const int nPages = GetNumberOfPages(); + const uint32_t nPages = m_pLinearized->GetPageCount(); if (nPages < 1 || nPages >= FPDF_PAGE_MAX_NUM) return false; @@ -148,7 +141,7 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { if (!CanReadFromBitStream(hStream, required_bits)) return false; - for (int i = 0; i < nPages; ++i) { + for (uint32_t i = 0; i < nPages; ++i) { FX_SAFE_UINT32 safeDeltaObj = hStream->GetBits(dwDeltaObjectsBits); safeDeltaObj += dwObjLeastNum; if (!safeDeltaObj.IsValid()) @@ -163,7 +156,7 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { return false; std::vector dwPageLenArray; - for (int i = 0; i < nPages; ++i) { + for (uint32_t i = 0; i < nPages; ++i) { FX_SAFE_UINT32 safePageLen = hStream->GetBits(dwDeltaPageLenBits); safePageLen += dwPageLeastLen; if (!safePageLen.IsValid()) @@ -172,15 +165,9 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { dwPageLenArray.push_back(safePageLen.ValueOrDie()); } - int nOffsetE = GetEndOfFirstPageOffset(); - if (nOffsetE < 0) - return false; - - int nFirstPageNum = GetFirstPageNumber(); - if (nFirstPageNum < 0 || nFirstPageNum > std::numeric_limits::max() - 1) - return false; - - for (int i = 0; i < nPages; ++i) { + const FX_FILESIZE nOffsetE = m_pLinearized->GetFirstPageEndOffset(); + const uint32_t nFirstPageNum = m_pLinearized->GetFirstPageNo(); + for (uint32_t i = 0; i < nPages; ++i) { if (i == nFirstPageNum) { m_szPageOffsetArray.push_back(m_szFirstPageObjOffset); } else if (i == nFirstPageNum + 1) { @@ -210,12 +197,12 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { if (!CanReadFromBitStream(hStream, required_bits)) return false; - for (int i = 0; i < nPages; i++) + for (uint32_t i = 0; i < nPages; i++) m_dwNSharedObjsArray.push_back(hStream->GetBits(dwSharedObjBits)); hStream->ByteAlign(); // Array of identifiers, size = nshared_objects. - for (int i = 0; i < nPages; i++) { + for (uint32_t i = 0; i < nPages; i++) { required_bits = dwSharedIdBits; required_bits *= m_dwNSharedObjsArray[i]; if (!CanReadFromBitStream(hStream, required_bits)) @@ -226,7 +213,7 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { } hStream->ByteAlign(); - for (int i = 0; i < nPages; i++) { + for (uint32_t i = 0; i < nPages; i++) { FX_SAFE_UINT32 safeSize = m_dwNSharedObjsArray[i]; safeSize *= dwSharedNumeratorBits; if (!CanReadFromBitStream(hStream, safeSize)) @@ -251,10 +238,8 @@ bool CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, if (!hStream || hStream->IsEOF()) return false; - int nStreamOffset = ReadPrimaryHintStreamOffset(); - int nStreamLen = ReadPrimaryHintStreamLength(); - if (nStreamOffset < 0 || nStreamLen < 1) - return false; + const FX_FILESIZE nStreamOffset = m_pLinearized->GetHintStart(); + const uint32_t nStreamLen = m_pLinearized->GetHintLength(); FX_SAFE_UINT32 bit_offset = offset; bit_offset *= 8; @@ -304,9 +289,7 @@ bool CPDF_HintTables::ReadSharedObjHintTable(CFX_BitStream* hStream, return false; } - int nFirstPageObjNum = GetFirstPageObjectNumber(); - if (nFirstPageObjNum < 0) - return false; + const uint32_t nFirstPageObjNum = m_pLinearized->GetFirstPageObjNum(); uint32_t dwPrevObjLen = 0; uint32_t dwCurObjLen = 0; @@ -381,15 +364,9 @@ bool CPDF_HintTables::GetPagePos(uint32_t index, *szPageStartPos = m_szPageOffsetArray[index]; *szPageLength = GetItemLength(index, m_szPageOffsetArray); - int nFirstPageObjNum = GetFirstPageObjectNumber(); - if (nFirstPageObjNum < 0) - return false; + const uint32_t nFirstPageObjNum = m_pLinearized->GetFirstPageObjNum(); - int nFirstPageNum = GetFirstPageNumber(); - if (!pdfium::base::IsValueInRangeForNumericType(nFirstPageNum)) - return false; - - uint32_t dwFirstPageNum = static_cast(nFirstPageNum); + const uint32_t dwFirstPageNum = m_pLinearized->GetFirstPageNo(); if (index == dwFirstPageNum) { *dwObjNum = nFirstPageObjNum; return true; @@ -406,11 +383,7 @@ bool CPDF_HintTables::GetPagePos(uint32_t index, } CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(uint32_t index) { - int nFirstPageNum = GetFirstPageNumber(); - if (!pdfium::base::IsValueInRangeForNumericType(nFirstPageNum)) - return CPDF_DataAvail::DataError; - - if (index == static_cast(nFirstPageNum)) + if (index == m_pLinearized->GetFirstPageNo()) return CPDF_DataAvail::DataAvailable; uint32_t dwLength = GetItemLength(index, m_szPageOffsetArray); @@ -428,9 +401,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(uint32_t index) { for (uint32_t i = 0; i < index; ++i) offset += m_dwNSharedObjsArray[i]; - int nFirstPageObjNum = GetFirstPageObjectNumber(); - if (nFirstPageObjNum < 0) - return CPDF_DataAvail::DataError; + const uint32_t nFirstPageObjNum = m_pLinearized->GetFirstPageObjNum(); uint32_t dwIndex = 0; uint32_t dwObjNum = 0; @@ -460,7 +431,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(uint32_t index) { } bool CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { - if (!pHintStream) + if (!pHintStream || !m_pLinearized->HasHintTable()) return false; CPDF_Dictionary* pDict = pHintStream->GetDict(); @@ -493,27 +464,3 @@ bool CPDF_HintTables::LoadHintStream(CPDF_Stream* pHintStream) { return ReadPageHintTable(&bs) && ReadSharedObjHintTable(&bs, shared_hint_table_offset); } - -int CPDF_HintTables::GetEndOfFirstPageOffset() const { - return static_cast(m_pLinearized->GetFirstPageEndOffset()); -} - -int CPDF_HintTables::GetNumberOfPages() const { - return static_cast(m_pLinearized->GetPageCount()); -} - -int CPDF_HintTables::GetFirstPageObjectNumber() const { - return static_cast(m_pLinearized->GetFirstPageObjNum()); -} - -int CPDF_HintTables::GetFirstPageNumber() const { - return static_cast(m_pLinearized->GetFirstPageNo()); -} - -int CPDF_HintTables::ReadPrimaryHintStreamOffset() const { - return static_cast(m_pLinearized->GetHintStart()); -} - -int CPDF_HintTables::ReadPrimaryHintStreamLength() const { - return static_cast(m_pLinearized->GetHintLength()); -} diff --git a/core/fpdfapi/parser/cpdf_hint_tables.h b/core/fpdfapi/parser/cpdf_hint_tables.h index d5feb4638c..3664e1517c 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.h +++ b/core/fpdfapi/parser/cpdf_hint_tables.h @@ -38,14 +38,6 @@ class CPDF_HintTables { bool ReadSharedObjHintTable(CFX_BitStream* hStream, uint32_t offset); private: - // Tests can override. - virtual int GetEndOfFirstPageOffset() const; - virtual int GetNumberOfPages() const; - virtual int GetFirstPageObjectNumber() const; - virtual int GetFirstPageNumber() const; - virtual int ReadPrimaryHintStreamOffset() const; - virtual int ReadPrimaryHintStreamLength() const; - uint32_t GetItemLength(uint32_t index, const std::vector& szArray) const; -- cgit v1.2.3