Unify CPDF_DataAvail::CheckEnd.

Use read validator to check "startxref" availability.

Change-Id: I258a707e4269fe768898d74db0955302b34ccf34
Reviewed-on: https://pdfium-review.googlesource.com/11711
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 93e4472..d298fb7 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -270,7 +270,7 @@
     case PDF_DATAAVAIL_HINTTABLE:
       return CheckHintTables(pHints);
     case PDF_DATAAVAIL_END:
-      return CheckEnd(pHints);
+      return CheckEnd();
     case PDF_DATAAVAIL_CROSSREF:
       return CheckCrossRef(pHints);
     case PDF_DATAAVAIL_CROSSREF_ITEM:
@@ -743,16 +743,17 @@
   return true;
 }
 
-bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) {
-  uint32_t req_pos = (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0);
-  uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos);
-  if (!m_pFileAvail->IsDataAvail(req_pos, dwSize)) {
-    pHints->AddSegment(req_pos, dwSize);
-    return false;
-  }
-
+bool CPDF_DataAvail::CheckEnd() {
+  const uint32_t req_pos =
+      (uint32_t)(m_dwFileLen > 1024 ? m_dwFileLen - 1024 : 0);
+  const uint32_t dwSize = (uint32_t)(m_dwFileLen - req_pos);
   std::vector<uint8_t> buffer(dwSize);
-  m_pFileRead->ReadBlock(buffer.data(), req_pos, dwSize);
+  {
+    const CPDF_ReadValidator::Session read_session(GetValidator().Get());
+    m_pFileRead->ReadBlock(buffer.data(), req_pos, dwSize);
+    if (GetValidator()->has_read_problems())
+      return false;
+  }
 
   auto file = pdfium::MakeRetain<CFX_MemoryStream>(
       buffer.data(), static_cast<size_t>(dwSize), false);
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h
index dec6b30..fe7b26b 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.h
+++ b/core/fpdfapi/parser/cpdf_data_avail.h
@@ -133,7 +133,7 @@
   bool CheckHeader();
   bool CheckFirstPage(DownloadHints* pHints);
   bool CheckHintTables(DownloadHints* pHints);
-  bool CheckEnd(DownloadHints* pHints);
+  bool CheckEnd();
   bool CheckCrossRef(DownloadHints* pHints);
   bool CheckCrossRefItem();
   bool CheckTrailer(DownloadHints* pHints);