summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp27
-rw-r--r--core/fpdfapi/parser/cpdf_hint_tables.cpp34
-rw-r--r--core/fpdfapi/parser/cpdf_hint_tables.h8
3 files changed, 48 insertions, 21 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 41d410a87b..904b0ad9fc 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -437,30 +437,17 @@ bool CPDF_DataAvail::CheckFirstPage() {
}
bool CPDF_DataAvail::CheckHintTables() {
- if (m_pLinearized->GetPageCount() <= 1) {
- m_docStatus = PDF_DATAAVAIL_DONE;
- return true;
- }
- if (!m_pLinearized->HasHintTable()) {
+ const CPDF_ReadValidator::Session read_session(GetValidator().Get());
+ m_pHintTables =
+ CPDF_HintTables::Parse(GetSyntaxParser(), m_pLinearized.get());
+
+ if (GetValidator()->read_error()) {
m_docStatus = PDF_DATAAVAIL_ERROR;
- return false;
+ return true;
}
-
- const FX_FILESIZE szHintStart = m_pLinearized->GetHintStart();
- const uint32_t szHintLength = m_pLinearized->GetHintLength();
-
- if (!GetValidator()->CheckDataRangeAndRequestIfUnavailable(szHintStart,
- szHintLength))
+ if (GetValidator()->has_unavailable_data())
return false;
- auto pHintTables = pdfium::MakeUnique<CPDF_HintTables>(GetValidator().Get(),
- m_pLinearized.get());
- std::unique_ptr<CPDF_Object> pHintStream =
- ParseIndirectObjectAt(szHintStart, 0);
- CPDF_Stream* pStream = ToStream(pHintStream.get());
- if (pStream && pHintTables->LoadHintStream(pStream))
- m_pHintTables = std::move(pHintTables);
-
m_docStatus = PDF_DATAAVAIL_DONE;
return true;
}
diff --git a/core/fpdfapi/parser/cpdf_hint_tables.cpp b/core/fpdfapi/parser/cpdf_hint_tables.cpp
index 71fb6e2843..43c3138605 100644
--- a/core/fpdfapi/parser/cpdf_hint_tables.cpp
+++ b/core/fpdfapi/parser/cpdf_hint_tables.cpp
@@ -16,6 +16,7 @@
#include "core/fpdfapi/parser/cpdf_read_validator.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
+#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
#include "core/fxcrt/cfx_bitstream.h"
#include "core/fxcrt/fx_safe_types.h"
#include "third_party/base/numerics/safe_conversions.h"
@@ -40,6 +41,39 @@ bool IsValidPageOffsetHintTableBitCount(uint32_t bits) {
CPDF_HintTables::PageInfo::PageInfo() = default;
CPDF_HintTables::PageInfo::~PageInfo() = default;
+// static
+std::unique_ptr<CPDF_HintTables> CPDF_HintTables::Parse(
+ CPDF_SyntaxParser* parser,
+ CPDF_LinearizedHeader* pLinearized) {
+ ASSERT(parser);
+ if (!pLinearized || pLinearized->GetPageCount() <= 1 ||
+ !pLinearized->HasHintTable()) {
+ return nullptr;
+ }
+
+ const FX_FILESIZE szHintStart = pLinearized->GetHintStart();
+ const uint32_t szHintLength = pLinearized->GetHintLength();
+
+ if (!parser->GetValidator()->CheckDataRangeAndRequestIfUnavailable(
+ szHintStart, szHintLength)) {
+ return nullptr;
+ }
+
+ parser->SetPos(szHintStart);
+ std::unique_ptr<CPDF_Stream> hints_stream = ToStream(
+ parser->GetIndirectObject(nullptr, CPDF_SyntaxParser::ParseType::kLoose));
+
+ if (!hints_stream)
+ return nullptr;
+
+ auto pHintTables = pdfium::MakeUnique<CPDF_HintTables>(
+ parser->GetValidator().Get(), pLinearized);
+ if (!pHintTables->LoadHintStream(hints_stream.get()))
+ return nullptr;
+
+ return pHintTables;
+}
+
CPDF_HintTables::CPDF_HintTables(CPDF_ReadValidator* pValidator,
CPDF_LinearizedHeader* pLinearized)
: m_pValidator(pValidator),
diff --git a/core/fpdfapi/parser/cpdf_hint_tables.h b/core/fpdfapi/parser/cpdf_hint_tables.h
index 20ba9be051..6b6a5897eb 100644
--- a/core/fpdfapi/parser/cpdf_hint_tables.h
+++ b/core/fpdfapi/parser/cpdf_hint_tables.h
@@ -7,6 +7,7 @@
#ifndef CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_
#define CORE_FPDFAPI_PARSER_CPDF_HINT_TABLES_H_
+#include <memory>
#include <vector>
#include "core/fpdfapi/parser/cpdf_data_avail.h"
@@ -15,8 +16,9 @@
class CFX_BitStream;
class CPDF_LinearizedHeader;
-class CPDF_Stream;
class CPDF_ReadValidator;
+class CPDF_Stream;
+class CPDF_SyntaxParser;
class CPDF_HintTables {
public:
@@ -67,6 +69,10 @@ class CPDF_HintTables {
PageInfo& operator=(const PageInfo&) = delete;
};
+ static std::unique_ptr<CPDF_HintTables> Parse(
+ CPDF_SyntaxParser* parser,
+ CPDF_LinearizedHeader* pLinearized);
+
CPDF_HintTables(CPDF_ReadValidator* pValidator,
CPDF_LinearizedHeader* pLinearized);
virtual ~CPDF_HintTables();