Move CPDF_ModuleMgr::kFileBufSize to CPDF_Stream. Allow removing another circular include. Streams are more likely concenred about buffer sizes than a module manager would be in the first place. Change-Id: Ia046e424cf5da1112cf1684a90dbed8f4898a3a6 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/55395 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/BUILD.gn b/core/fpdfapi/BUILD.gn index 9ebdab7..50409a5 100644 --- a/core/fpdfapi/BUILD.gn +++ b/core/fpdfapi/BUILD.gn
@@ -25,9 +25,6 @@ "parser", "render", ] - allow_circular_includes_from = [ - "page", - "parser", - ] + allow_circular_includes_from = [ "page" ] visibility = [ "../../*" ] }
diff --git a/core/fpdfapi/cpdf_modulemgr.h b/core/fpdfapi/cpdf_modulemgr.h index 70eb6f0..7bda93b 100644 --- a/core/fpdfapi/cpdf_modulemgr.h +++ b/core/fpdfapi/cpdf_modulemgr.h
@@ -29,7 +29,6 @@ static void Create(); static void Destroy(); static CPDF_ModuleMgr* Get(); - static const int kFileBufSize = 512; void SetUnsupportInfoAdapter( std::unique_ptr<fpdfapi::UnsupportedInfoAdapter> pAdapter) {
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index 2a3fac5..cdcb4ff 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -650,7 +650,7 @@ m_CrossRefTable = CPDF_CrossRefTable::MergeUp(std::move(m_CrossRefTable), std::move(cross_ref_table)); // Resore default buffer size. - m_pSyntax->SetReadBufferSize(CPDF_ModuleMgr::kFileBufSize); + m_pSyntax->SetReadBufferSize(CPDF_Stream::kFileBufSize); return GetTrailer() && !m_CrossRefTable->objects_info().empty(); }
diff --git a/core/fpdfapi/parser/cpdf_read_validator.cpp b/core/fpdfapi/parser/cpdf_read_validator.cpp index 67958de..61d7d19 100644 --- a/core/fpdfapi/parser/cpdf_read_validator.cpp +++ b/core/fpdfapi/parser/cpdf_read_validator.cpp
@@ -6,13 +6,13 @@ #include <algorithm> -#include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fxcrt/fx_safe_types.h" #include "third_party/base/logging.h" namespace { -constexpr FX_FILESIZE kAlignBlockValue = CPDF_ModuleMgr::kFileBufSize; +constexpr FX_FILESIZE kAlignBlockValue = CPDF_Stream::kFileBufSize; FX_FILESIZE AlignDown(FX_FILESIZE offset) { return offset > 0 ? (offset - offset % kAlignBlockValue) : 0; @@ -133,7 +133,7 @@ FX_SAFE_FILESIZE end_segment_offset = offset; end_segment_offset += size; // Increase checked range to allow CPDF_SyntaxParser read whole buffer. - end_segment_offset += CPDF_ModuleMgr::kFileBufSize; + end_segment_offset += CPDF_Stream::kFileBufSize; if (!end_segment_offset.IsValid()) { NOTREACHED(); return false;
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h index d76b683..29c4bfb 100644 --- a/core/fpdfapi/parser/cpdf_stream.h +++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -16,6 +16,8 @@ class CPDF_Stream final : public CPDF_Object { public: + static const int kFileBufSize = 512; + template <typename T, typename... Args> friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp index 0109019..50014cd 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -148,8 +148,8 @@ if (!IsPositionRead(pos)) { FX_FILESIZE block_start = 0; - if (pos >= CPDF_ModuleMgr::kFileBufSize) - block_start = pos - CPDF_ModuleMgr::kFileBufSize + 1; + if (pos >= CPDF_Stream::kFileBufSize) + block_start = pos - CPDF_Stream::kFileBufSize + 1; if (!ReadBlockAt(block_start) || !IsPositionRead(pos)) return false; }
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h index 14b5057..d36aedf 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser.h +++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -10,7 +10,7 @@ #include <memory> #include <vector> -#include "core/fpdfapi/cpdf_modulemgr.h" +#include "core/fpdfapi/parser/cpdf_stream.h" #include "core/fxcrt/string_pool_template.h" #include "core/fxcrt/weak_ptr.h" @@ -113,7 +113,7 @@ FX_FILESIZE m_BufOffset = 0; uint32_t m_WordSize = 0; uint8_t m_WordBuffer[257]; - uint32_t m_ReadBufferSize = CPDF_ModuleMgr::kFileBufSize; + uint32_t m_ReadBufferSize = CPDF_Stream::kFileBufSize; }; #endif // CORE_FPDFAPI_PARSER_CPDF_SYNTAX_PARSER_H_