summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2018-08-02 19:19:27 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-02 19:19:27 +0000
commit2d2b9934996277801a63bb0670899030dcdbcd35 (patch)
tree80dd13b8d4846640bd549543e720268258a3af40 /core/fpdfapi
parente89d258be505877a6f73d36b3b84a41e4ee37ea8 (diff)
downloadpdfium-2d2b9934996277801a63bb0670899030dcdbcd35.tar.xz
Rework of CPDF_DataAvail::CheckHintTables.
Move HintTables parsing logic into CPDF_HintTables. Change-Id: I9748179fe9fc3ac44f88c19c347e30c0e7e3ac67 Reviewed-on: https://pdfium-review.googlesource.com/38771 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi')
-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();