diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2017-09-08 18:10:01 +0300 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-09-19 00:15:50 +0000 |
commit | 2c559dc576392e69208895f2632f49ee43903d48 (patch) | |
tree | 0d9d281df2dd854f09e44f3e0dfab40f76c07cf8 /core/fpdfapi/parser | |
parent | 0bf6961663ec38568b9323e66a8c808d9aa726fb (diff) | |
download | pdfium-2c559dc576392e69208895f2632f49ee43903d48.tar.xz |
Use CPDF_ReadValidator to request linearized hint tables.
Change-Id: I9ecf08c5cabfeb7b354abeb46b94918ae0b4539a
Reviewed-on: https://pdfium-review.googlesource.com/13590
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 25 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.h | 6 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_hint_tables.cpp | 13 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_hint_tables.h | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_linearized_header.cpp | 4 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_linearized_header.h | 5 |
6 files changed, 24 insertions, 33 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 4fa419c22a..bbd61dda00 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -207,7 +207,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsDocAvail( const HintsScope hints_scope(m_pFileRead.Get(), pHints); while (!m_bDocAvail) { - if (!CheckDocStatus(pHints)) + if (!CheckDocStatus()) return DataNotAvailable; } @@ -261,14 +261,14 @@ bool CPDF_DataAvail::CheckAcroForm() { return true; } -bool CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { +bool CPDF_DataAvail::CheckDocStatus() { switch (m_docStatus) { case PDF_DATAAVAIL_HEADER: return CheckHeader(); case PDF_DATAAVAIL_FIRSTPAGE: return CheckFirstPage(); case PDF_DATAAVAIL_HINTTABLE: - return CheckHintTables(pHints); + return CheckHintTables(); case PDF_DATAAVAIL_END: return CheckEnd(); case PDF_DATAAVAIL_CROSSREF: @@ -601,9 +601,7 @@ bool CPDF_DataAvail::CheckFirstPage() { return true; } -bool CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, - uint32_t size, - DownloadHints* pHints) { +bool CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, uint32_t size) { if (offset < 0 || offset > m_dwFileLen) return true; @@ -615,15 +613,14 @@ bool CPDF_DataAvail::IsDataAvail(FX_FILESIZE offset, else size += 512; - if (!m_pFileAvail->IsDataAvail(offset, size)) { - if (pHints) - pHints->AddSegment(offset, size); + if (!GetValidator()->IsDataRangeAvailable(offset, size)) { + GetValidator()->ScheduleDataDownload(offset, size); return false; } return true; } -bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { +bool CPDF_DataAvail::CheckHintTables() { if (m_pLinearized->GetPageCount() <= 1) { m_docStatus = PDF_DATAAVAIL_DONE; return true; @@ -633,10 +630,10 @@ bool CPDF_DataAvail::CheckHintTables(DownloadHints* pHints) { return false; } - FX_FILESIZE szHintStart = m_pLinearized->GetHintStart(); - FX_FILESIZE szHintLength = m_pLinearized->GetHintLength(); + const FX_FILESIZE szHintStart = m_pLinearized->GetHintStart(); + const uint32_t szHintLength = m_pLinearized->GetHintLength(); - if (!IsDataAvail(szHintStart, szHintLength, pHints)) + if (!IsDataAvail(szHintStart, szHintLength)) return false; m_syntaxParser.InitParser(m_pFileRead, m_dwHeaderOffset); @@ -1316,7 +1313,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( return nResult; if (m_pHintTables) { - nResult = m_pHintTables->CheckPage(dwPage, pHints); + nResult = m_pHintTables->CheckPage(dwPage); if (nResult != DataAvailable) return nResult; m_pagesLoadState.insert(dwPage); diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 8a93424d36..befb84f833 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -98,7 +98,7 @@ class CPDF_DataAvail final { bool bSupportHintTable); ~CPDF_DataAvail(); - bool IsDataAvail(FX_FILESIZE offset, uint32_t size, DownloadHints* pHints); + bool IsDataAvail(FX_FILESIZE offset, uint32_t size); DocAvailStatus IsDocAvail(DownloadHints* pHints); void SetDocument(CPDF_Document* pDoc); DocAvailStatus IsPageAvail(uint32_t dwPage, DownloadHints* pHints); @@ -126,10 +126,10 @@ class CPDF_DataAvail final { bool AreObjectsAvailable(std::vector<CPDF_Object*>& obj_array, bool bParsePage, std::vector<CPDF_Object*>& ret_array); - bool CheckDocStatus(DownloadHints* pHints); + bool CheckDocStatus(); bool CheckHeader(); bool CheckFirstPage(); - bool CheckHintTables(DownloadHints* pHints); + bool CheckHintTables(); bool CheckEnd(); bool CheckCrossRef(); bool CheckCrossRefItem(); diff --git a/core/fpdfapi/parser/cpdf_hint_tables.cpp b/core/fpdfapi/parser/cpdf_hint_tables.cpp index deffe5cb38..7a5eb2397b 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/parser/cpdf_hint_tables.cpp @@ -400,12 +400,7 @@ bool CPDF_HintTables::GetPagePos(uint32_t index, return true; } -CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( - uint32_t index, - CPDF_DataAvail::DownloadHints* pHints) { - if (!pHints) - return CPDF_DataAvail::DataError; - +CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage(uint32_t index) { int nFirstPageNum = GetFirstPageNumber(); if (!pdfium::base::IsValueInRangeForNumericType<uint32_t>(nFirstPageNum)) return CPDF_DataAvail::DataError; @@ -418,7 +413,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( if (!dwLength) return CPDF_DataAvail::DataError; - if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength, pHints)) + if (!m_pDataAvail->IsDataAvail(m_szPageOffsetArray[index], dwLength)) return CPDF_DataAvail::DataNotAvailable; // Download data of shared objects in the page. @@ -449,8 +444,8 @@ CPDF_DataAvail::DocAvailStatus CPDF_HintTables::CheckPage( if (!dwLength) return CPDF_DataAvail::DataError; - if (!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], dwLength, - pHints)) { + if (!m_pDataAvail->IsDataAvail(m_szSharedObjOffsetArray[dwIndex], + dwLength)) { return CPDF_DataAvail::DataNotAvailable; } } diff --git a/core/fpdfapi/parser/cpdf_hint_tables.h b/core/fpdfapi/parser/cpdf_hint_tables.h index 2ab42a93cf..e9647b1796 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.h +++ b/core/fpdfapi/parser/cpdf_hint_tables.h @@ -28,9 +28,7 @@ class CPDF_HintTables { FX_FILESIZE* szPageLength, uint32_t* dwObjNum); - CPDF_DataAvail::DocAvailStatus CheckPage( - uint32_t index, - CPDF_DataAvail::DownloadHints* pHints); + CPDF_DataAvail::DocAvailStatus CheckPage(uint32_t index); bool LoadHintStream(CPDF_Stream* pHintStream); diff --git a/core/fpdfapi/parser/cpdf_linearized_header.cpp b/core/fpdfapi/parser/cpdf_linearized_header.cpp index a56d64f259..4d0b0e0acc 100644 --- a/core/fpdfapi/parser/cpdf_linearized_header.cpp +++ b/core/fpdfapi/parser/cpdf_linearized_header.cpp @@ -61,7 +61,9 @@ CPDF_LinearizedHeader::CPDF_LinearizedHeader(const CPDF_Dictionary* pDict) { pHintStreamRange ? pHintStreamRange->GetCount() : 0; if (nHintStreamSize == 2 || nHintStreamSize == 4) { m_szHintStart = std::max(pHintStreamRange->GetIntegerAt(0), 0); - m_szHintLength = std::max(pHintStreamRange->GetIntegerAt(1), 0); + const FX_SAFE_UINT32 safe_hint_length = pHintStreamRange->GetIntegerAt(1); + if (safe_hint_length.IsValid()) + m_HintLength = safe_hint_length.ValueOrDie(); } } diff --git a/core/fpdfapi/parser/cpdf_linearized_header.h b/core/fpdfapi/parser/cpdf_linearized_header.h index 0d6d725f00..79795b872f 100644 --- a/core/fpdfapi/parser/cpdf_linearized_header.h +++ b/core/fpdfapi/parser/cpdf_linearized_header.h @@ -35,8 +35,7 @@ class CPDF_LinearizedHeader { bool HasHintTable() const; // Will only return values > 0. FX_FILESIZE GetHintStart() const { return m_szHintStart; } - // Will only return values > 0. - FX_FILESIZE GetHintLength() const { return m_szHintLength; } + uint32_t GetHintLength() const { return m_HintLength; } protected: explicit CPDF_LinearizedHeader(const CPDF_Dictionary* pDict); @@ -49,7 +48,7 @@ class CPDF_LinearizedHeader { FX_FILESIZE m_szFirstPageEndOffset = 0; uint32_t m_FirstPageObjNum = 0; FX_FILESIZE m_szHintStart = 0; - FX_FILESIZE m_szHintLength = 0; + uint32_t m_HintLength = 0; }; #endif // CORE_FPDFAPI_PARSER_CPDF_LINEARIZED_HEADER_H_ |