diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2018-08-02 19:19:27 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-08-02 19:19:27 +0000 |
commit | 2d2b9934996277801a63bb0670899030dcdbcd35 (patch) | |
tree | 80dd13b8d4846640bd549543e720268258a3af40 /core/fpdfapi/parser/cpdf_hint_tables.cpp | |
parent | e89d258be505877a6f73d36b3b84a41e4ee37ea8 (diff) | |
download | pdfium-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/parser/cpdf_hint_tables.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_hint_tables.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
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), |