From 03371b8bb8459b96ceefa89d6b5ba2d08683614b Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Wed, 23 Aug 2017 17:53:13 +0300 Subject: Unify CPDF_DataAvail::CheckCrossRef. Use read validator to check cross ref table availability Change-Id: I050c366a255598ca6d8bcd353afa94c4a09c33a9 Reviewed-on: https://pdfium-review.googlesource.com/11730 Commit-Queue: dsinclair Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_data_avail.cpp | 15 +++++++-------- core/fpdfapi/parser/cpdf_data_avail.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 24ba2e28b1..234a5a0b19 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -58,7 +58,6 @@ class HintsScope { CPDF_DataAvail::DownloadHints* hints) : validator_(validator) { ASSERT(validator_); - validator_->ResetErrors(); validator_->SetDownloadHints(hints); } @@ -272,7 +271,7 @@ bool CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { case PDF_DATAAVAIL_END: return CheckEnd(); case PDF_DATAAVAIL_CROSSREF: - return CheckCrossRef(pHints); + return CheckCrossRef(); case PDF_DATAAVAIL_CROSSREF_ITEM: return CheckCrossRefItem(); case PDF_DATAAVAIL_TRAILER: @@ -890,8 +889,9 @@ bool CPDF_DataAvail::GetNextChar(uint8_t& ch) { bool CPDF_DataAvail::CheckCrossRefItem() { CFX_ByteString token; while (1) { + const CPDF_ReadValidator::Session read_session(GetValidator().Get()); if (!GetNextToken(&token)) { - if (!m_pFileRead->has_read_problems()) + if (!GetValidator()->has_read_problems()) m_docStatus = PDF_DATAAVAIL_ERROR; return false; } @@ -904,13 +904,12 @@ bool CPDF_DataAvail::CheckCrossRefItem() { } } -bool CPDF_DataAvail::CheckCrossRef(DownloadHints* pHints) { - int32_t iSize = 0; +bool CPDF_DataAvail::CheckCrossRef() { + const CPDF_ReadValidator::Session read_session(GetValidator().Get()); CFX_ByteString token; if (!GetNextToken(&token)) { - iSize = static_cast(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos - : 512); - pHints->AddSegment(m_Pos, iSize); + if (!GetValidator()->has_read_problems()) + m_docStatus = PDF_DATAAVAIL_ERROR; return false; } diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index db134dd3f5..e704e12900 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -133,7 +133,7 @@ class CPDF_DataAvail final { bool CheckFirstPage(DownloadHints* pHints); bool CheckHintTables(DownloadHints* pHints); bool CheckEnd(); - bool CheckCrossRef(DownloadHints* pHints); + bool CheckCrossRef(); bool CheckCrossRefItem(); bool CheckTrailer(DownloadHints* pHints); bool CheckRoot(); -- cgit v1.2.3