summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-13 23:19:29 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-13 23:19:29 +0000
commited176992eb7ddbb0fee7b79625501df06f8ccf93 (patch)
treeab5493b058e80da342648fda8b0cc8a8ba6cab94
parentf0260b2cccb9e6c59413a20040dccf5551fb6882 (diff)
downloadpdfium-ed176992eb7ddbb0fee7b79625501df06f8ccf93.tar.xz
Make CFX_ReadOnlyMemoryStream take a span.
Change-Id: Id097320ab2d9b5d1579582e5797e29c701499501 Reviewed-on: https://pdfium-review.googlesource.com/39991 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--core/fpdfapi/parser/cfdf_document.cpp3
-rw-r--r--core/fpdfdoc/cpdf_metadata.cpp3
-rw-r--r--core/fxcrt/cfx_readonlymemorystream.cpp16
-rw-r--r--core/fxcrt/cfx_readonlymemorystream.h6
-rw-r--r--fpdfsdk/fpdf_view.cpp8
-rw-r--r--testing/fuzzers/pdf_xml_fuzzer.cc4
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_document_parser.cpp4
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp9
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale.cpp3
10 files changed, 30 insertions, 30 deletions
diff --git a/core/fpdfapi/parser/cfdf_document.cpp b/core/fpdfapi/parser/cfdf_document.cpp
index d37c8d5457..421af48d80 100644
--- a/core/fpdfapi/parser/cfdf_document.cpp
+++ b/core/fpdfapi/parser/cfdf_document.cpp
@@ -32,8 +32,7 @@ std::unique_ptr<CFDF_Document> CFDF_Document::CreateNewDoc() {
std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(
pdfium::span<const uint8_t> span) {
auto pDoc = pdfium::MakeUnique<CFDF_Document>();
- pDoc->ParseStream(
- pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(span.data(), span.size()));
+ pDoc->ParseStream(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(span));
return pDoc->m_pRootDict ? std::move(pDoc) : nullptr;
}
diff --git a/core/fpdfdoc/cpdf_metadata.cpp b/core/fpdfdoc/cpdf_metadata.cpp
index b9a92963dd..99fd965452 100644
--- a/core/fpdfdoc/cpdf_metadata.cpp
+++ b/core/fpdfdoc/cpdf_metadata.cpp
@@ -67,8 +67,7 @@ std::vector<UnsupportedFeature> CPDF_Metadata::CheckForSharedForm() const {
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(stream_.Get());
pAcc->LoadAllDataFiltered();
- auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pAcc->GetData(),
- pAcc->GetSize());
+ auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pAcc->GetSpan());
CFX_XMLParser parser(stream);
std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
if (!doc)
diff --git a/core/fxcrt/cfx_readonlymemorystream.cpp b/core/fxcrt/cfx_readonlymemorystream.cpp
index 1d09759208..a01ed2e474 100644
--- a/core/fxcrt/cfx_readonlymemorystream.cpp
+++ b/core/fxcrt/cfx_readonlymemorystream.cpp
@@ -8,14 +8,14 @@
#include "core/fxcrt/fx_safe_types.h"
-CFX_ReadOnlyMemoryStream::CFX_ReadOnlyMemoryStream(const uint8_t* pBuf,
- FX_FILESIZE size)
- : m_pBuf(pBuf), m_size(size) {}
+CFX_ReadOnlyMemoryStream::CFX_ReadOnlyMemoryStream(
+ pdfium::span<const uint8_t> span)
+ : m_span(span) {}
CFX_ReadOnlyMemoryStream::~CFX_ReadOnlyMemoryStream() = default;
FX_FILESIZE CFX_ReadOnlyMemoryStream::GetSize() {
- return m_size;
+ return pdfium::base::checked_cast<FX_FILESIZE>(m_span.size());
}
bool CFX_ReadOnlyMemoryStream::ReadBlock(void* buffer,
@@ -24,11 +24,11 @@ bool CFX_ReadOnlyMemoryStream::ReadBlock(void* buffer,
if (offset < 0)
return false;
- FX_SAFE_FILESIZE newPos = pdfium::base::checked_cast<FX_FILESIZE>(size);
- newPos += offset;
- if (!newPos.IsValid() || newPos.ValueOrDie() > m_size)
+ FX_SAFE_SIZE_T pos = size;
+ pos += offset;
+ if (!pos.IsValid() || pos.ValueOrDie() > m_span.size())
return false;
- memcpy(buffer, m_pBuf + offset, size);
+ memcpy(buffer, &m_span[offset], size);
return true;
}
diff --git a/core/fxcrt/cfx_readonlymemorystream.h b/core/fxcrt/cfx_readonlymemorystream.h
index e9d18222a4..a6645b82c7 100644
--- a/core/fxcrt/cfx_readonlymemorystream.h
+++ b/core/fxcrt/cfx_readonlymemorystream.h
@@ -9,6 +9,7 @@
#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/retain_ptr.h"
+#include "third_party/base/span.h"
class CFX_ReadOnlyMemoryStream final : public IFX_SeekableReadStream {
public:
@@ -20,11 +21,10 @@ class CFX_ReadOnlyMemoryStream final : public IFX_SeekableReadStream {
bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override;
private:
- CFX_ReadOnlyMemoryStream(const uint8_t* pBuf, FX_FILESIZE size);
+ explicit CFX_ReadOnlyMemoryStream(pdfium::span<const uint8_t> span);
~CFX_ReadOnlyMemoryStream() override;
- const uint8_t* const m_pBuf;
- const FX_FILESIZE m_size;
+ const pdfium::span<const uint8_t> m_span;
};
#endif // CORE_FXCRT_CFX_READONLYMEMORYSTREAM_H_
diff --git a/fpdfsdk/fpdf_view.cpp b/fpdfsdk/fpdf_view.cpp
index bd8cfe1e25..0cfa362904 100644
--- a/fpdfsdk/fpdf_view.cpp
+++ b/fpdfsdk/fpdf_view.cpp
@@ -41,6 +41,7 @@
#include "fxjs/ijs_runtime.h"
#include "public/fpdf_formfill.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/span.h"
#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
@@ -269,9 +270,10 @@ FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_LoadXFA(FPDF_DOCUMENT document) {
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password) {
- return LoadDocumentImpl(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
- static_cast<const uint8_t*>(data_buf), size),
- password);
+ return LoadDocumentImpl(
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ pdfium::make_span(static_cast<const uint8_t*>(data_buf), size)),
+ password);
}
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
diff --git a/testing/fuzzers/pdf_xml_fuzzer.cc b/testing/fuzzers/pdf_xml_fuzzer.cc
index 7f5fdb1532..efc171671c 100644
--- a/testing/fuzzers/pdf_xml_fuzzer.cc
+++ b/testing/fuzzers/pdf_xml_fuzzer.cc
@@ -13,13 +13,15 @@
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "core/fxcrt/xml/cfx_xmlparser.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/span.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FX_SAFE_SIZE_T safe_size = size;
if (!safe_size.IsValid())
return 0;
- auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(data, size);
+ auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ pdfium::make_span(data, size));
CFX_XMLParser parser(stream);
std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
if (!doc || !doc->GetRoot())
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index 7852d30036..44c1b7912b 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -215,8 +215,8 @@ RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage(
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
pAcc->LoadAllDataFiltered();
- auto pImageFileRead = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
- pAcc->GetData(), pAcc->GetSize());
+ auto pImageFileRead =
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pAcc->GetSpan());
RetainPtr<CFX_DIBitmap> pDibSource = XFA_LoadImageFromBuffer(
pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi);
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
index 5cb08863c8..d0f137da7c 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -332,8 +332,8 @@ bool CXFA_DocumentParser::Parse(
}
CFX_XMLNode* CXFA_DocumentParser::ParseXMLData(const ByteString& wsXML) {
- auto pStream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
- wsXML.raw_str(), wsXML.GetLength());
+ auto pStream =
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(wsXML.AsRawSpan());
xml_doc_ = LoadXML(pStream);
if (!xml_doc_)
return nullptr;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 06bbb0936a..a60e66584b 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -29,6 +29,7 @@
#include "third_party/base/compiler_specific.h"
#include "third_party/base/logging.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/span.h"
#include "third_party/base/stl_util.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fgas/font/cfgas_fontmgr.h"
@@ -199,7 +200,6 @@ RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
return nullptr;
FXCODEC_IMAGE_TYPE type = XFA_GetImageType(pImage->GetContentType());
- ByteString bsContent;
std::vector<uint8_t> buffer;
RetainPtr<IFX_SeekableReadStream> pImageFileRead;
if (wsImage.GetLength() > 0) {
@@ -209,13 +209,12 @@ RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
buffer.resize(bsData.GetLength());
int32_t iRead = XFA_Base64Decode(bsData.c_str(), buffer.data());
if (iRead > 0) {
- pImageFileRead =
- pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(buffer.data(), iRead);
+ pImageFileRead = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ pdfium::make_span(buffer.data(), iRead));
}
} else {
- bsContent = wsImage.ToDefANSI();
pImageFileRead = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
- bsContent.raw_str(), bsContent.GetLength());
+ wsImage.ToDefANSI().AsRawSpan());
}
} else {
WideString wsURL = wsHref;
diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp
index 2806a084d6..20557dd59c 100644
--- a/xfa/fxfa/parser/cxfa_xmllocale.cpp
+++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp
@@ -31,8 +31,7 @@ constexpr wchar_t kCurrencySymbol[] = L"currencySymbol";
// static
std::unique_ptr<CXFA_XMLLocale> CXFA_XMLLocale::Create(
pdfium::span<uint8_t> data) {
- auto stream =
- pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(data.data(), data.size());
+ auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(data);
CFX_XMLParser parser(stream);
auto doc = parser.Parse();
if (!doc)