From 53894390dba2ec571bab75157ebe60d11171ed07 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 9 Apr 2018 18:30:24 +0000 Subject: Use pdfium::span<> in CFX_BitStream, CPDF_SimpleParser. Get bounds checks in parsers automatically when using spans. Change-Id: I71fbe7b838435d455376db2f89817d807a9cdcfd Reviewed-on: https://pdfium-review.googlesource.com/29830 Commit-Queue: Tom Sepez Reviewed-by: dsinclair --- core/fpdfapi/page/cpdf_meshstream.cpp | 5 +++-- core/fpdfapi/page/cpdf_psengine.cpp | 4 ++-- core/fpdfapi/page/cpdf_psengine.h | 3 ++- core/fpdfapi/page/cpdf_psfunc.cpp | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) (limited to 'core/fpdfapi/page') diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp index 083acce68a..579678af41 100644 --- a/core/fpdfapi/page/cpdf_meshstream.cpp +++ b/core/fpdfapi/page/cpdf_meshstream.cpp @@ -9,6 +9,7 @@ #include "core/fpdfapi/page/cpdf_colorspace.h" #include "core/fpdfapi/page/cpdf_function.h" #include "core/fpdfapi/parser/cpdf_array.h" +#include "third_party/base/span.h" namespace { @@ -117,8 +118,8 @@ CPDF_MeshStream::~CPDF_MeshStream() {} bool CPDF_MeshStream::Load() { m_pStream->LoadAllDataFiltered(); - m_BitStream = pdfium::MakeUnique(m_pStream->GetData(), - m_pStream->GetSize()); + m_BitStream = pdfium::MakeUnique( + pdfium::make_span(m_pStream->GetData(), m_pStream->GetSize())); CPDF_Dictionary* pDict = m_pShadingStream->GetDict(); m_nCoordBits = pDict->GetIntegerFor("BitsPerCoordinate"); m_nComponentBits = pDict->GetIntegerFor("BitsPerComponent"); diff --git a/core/fpdfapi/page/cpdf_psengine.cpp b/core/fpdfapi/page/cpdf_psengine.cpp index adfd45e877..7fa8cd3001 100644 --- a/core/fpdfapi/page/cpdf_psengine.cpp +++ b/core/fpdfapi/page/cpdf_psengine.cpp @@ -190,8 +190,8 @@ int CPDF_PSEngine::PopInt() { return static_cast(Pop()); } -bool CPDF_PSEngine::Parse(const ByteStringView& view) { - CPDF_SimpleParser parser(view); +bool CPDF_PSEngine::Parse(pdfium::span input) { + CPDF_SimpleParser parser(input); return parser.GetWord() == "{" && m_MainProc.Parse(&parser, 0); } diff --git a/core/fpdfapi/page/cpdf_psengine.h b/core/fpdfapi/page/cpdf_psengine.h index 042a1c0895..9cb1e1a291 100644 --- a/core/fpdfapi/page/cpdf_psengine.h +++ b/core/fpdfapi/page/cpdf_psengine.h @@ -12,6 +12,7 @@ #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" +#include "third_party/base/span.h" class CPDF_PSEngine; class CPDF_PSProc; @@ -109,7 +110,7 @@ class CPDF_PSEngine { CPDF_PSEngine(); ~CPDF_PSEngine(); - bool Parse(const ByteStringView& str); + bool Parse(pdfium::span input); bool Execute(); bool DoOperator(PDF_PSOP op); void Reset() { m_StackCount = 0; } diff --git a/core/fpdfapi/page/cpdf_psfunc.cpp b/core/fpdfapi/page/cpdf_psfunc.cpp index af996c056c..5499a47f99 100644 --- a/core/fpdfapi/page/cpdf_psfunc.cpp +++ b/core/fpdfapi/page/cpdf_psfunc.cpp @@ -16,7 +16,7 @@ CPDF_PSFunc::~CPDF_PSFunc() {} bool CPDF_PSFunc::v_Init(CPDF_Object* pObj) { auto pAcc = pdfium::MakeRetain(pObj->AsStream()); pAcc->LoadAllDataFiltered(); - return m_PS.Parse(pAcc->GetDataView()); + return m_PS.Parse(pAcc->GetSpan()); } bool CPDF_PSFunc::v_Call(float* inputs, float* results) const { -- cgit v1.2.3