summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-13 19:56:29 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-13 19:56:29 +0000
commit30029419ad4b9e5cd382767a8645677afbeff7fd (patch)
tree1b932ad14e5acf12aefdeeebac856ca8f5d89bfa
parent1a99f200c59a89fe297ac79658d2fe11b13b1553 (diff)
downloadpdfium-30029419ad4b9e5cd382767a8645677afbeff7fd.tar.xz
Use CFX_ReadOnlyMemoryStream in more places.
More const pointers, less const_casts. BUG=pdfium:263 Change-Id: I47fc6d8f2f837390e40ad22d8b67946065294eaa Reviewed-on: https://pdfium-review.googlesource.com/39879 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--core/fpdfapi/parser/cfdf_document.cpp11
-rw-r--r--core/fpdfapi/parser/cfdf_document.h2
-rw-r--r--testing/fuzzers/pdf_xml_fuzzer.cc6
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_document_parser.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp23
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale.cpp4
7 files changed, 26 insertions, 33 deletions
diff --git a/core/fpdfapi/parser/cfdf_document.cpp b/core/fpdfapi/parser/cfdf_document.cpp
index bfade94af6..cfed11b9cd 100644
--- a/core/fpdfapi/parser/cfdf_document.cpp
+++ b/core/fpdfapi/parser/cfdf_document.cpp
@@ -14,13 +14,12 @@
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
#include "core/fpdfapi/parser/fpdf_parser_utility.h"
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "third_party/base/ptr_util.h"
-CFDF_Document::CFDF_Document()
- : CPDF_IndirectObjectHolder(), m_pRootDict(nullptr) {}
+CFDF_Document::CFDF_Document() = default;
-CFDF_Document::~CFDF_Document() {}
+CFDF_Document::~CFDF_Document() = default;
std::unique_ptr<CFDF_Document> CFDF_Document::CreateNewDoc() {
auto pDoc = pdfium::MakeUnique<CFDF_Document>();
@@ -29,10 +28,10 @@ std::unique_ptr<CFDF_Document> CFDF_Document::CreateNewDoc() {
return pDoc;
}
-std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(uint8_t* pData,
+std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(const uint8_t* pData,
uint32_t size) {
auto pDoc = pdfium::MakeUnique<CFDF_Document>();
- pDoc->ParseStream(pdfium::MakeRetain<CFX_MemoryStream>(pData, size, false));
+ pDoc->ParseStream(pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(pData, size));
return pDoc->m_pRootDict ? std::move(pDoc) : nullptr;
}
diff --git a/core/fpdfapi/parser/cfdf_document.h b/core/fpdfapi/parser/cfdf_document.h
index b2cbd5bae9..c1c1b79636 100644
--- a/core/fpdfapi/parser/cfdf_document.h
+++ b/core/fpdfapi/parser/cfdf_document.h
@@ -19,7 +19,7 @@ class IFX_SeekableReadStream;
class CFDF_Document : public CPDF_IndirectObjectHolder {
public:
static std::unique_ptr<CFDF_Document> CreateNewDoc();
- static std::unique_ptr<CFDF_Document> ParseMemory(uint8_t* pData,
+ static std::unique_ptr<CFDF_Document> ParseMemory(const uint8_t* pData,
uint32_t size);
CFDF_Document();
diff --git a/testing/fuzzers/pdf_xml_fuzzer.cc b/testing/fuzzers/pdf_xml_fuzzer.cc
index a3c399f78d..7f5fdb1532 100644
--- a/testing/fuzzers/pdf_xml_fuzzer.cc
+++ b/testing/fuzzers/pdf_xml_fuzzer.cc
@@ -6,7 +6,7 @@
#include <cstdint>
#include <memory>
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
@@ -19,9 +19,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (!safe_size.IsValid())
return 0;
- auto stream = pdfium::MakeRetain<CFX_MemoryStream>(const_cast<uint8_t*>(data),
- size, false);
-
+ auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(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 330572ff9c..7852d30036 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -14,7 +14,7 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfdoc/cpdf_nametree.h"
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/cfx_seekablemultistream.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_memory.h"
@@ -215,9 +215,8 @@ RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage(
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
pAcc->LoadAllDataFiltered();
- RetainPtr<IFX_SeekableStream> pImageFileRead =
- pdfium::MakeRetain<CFX_MemoryStream>(
- const_cast<uint8_t*>(pAcc->GetData()), pAcc->GetSize(), false);
+ auto pImageFileRead = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ pAcc->GetData(), pAcc->GetSize());
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 96c031079b..5cb08863c8 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -10,7 +10,7 @@
#include <vector>
#include "core/fxcrt/autorestorer.h"
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/cfx_widetextbuf.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
@@ -332,8 +332,8 @@ bool CXFA_DocumentParser::Parse(
}
CFX_XMLNode* CXFA_DocumentParser::ParseXMLData(const ByteString& wsXML) {
- auto pStream = pdfium::MakeRetain<CFX_MemoryStream>(
- const_cast<uint8_t*>(wsXML.raw_str()), wsXML.GetLength(), false);
+ auto pStream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ wsXML.raw_str(), wsXML.GetLength());
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 8babe45ef3..06bbb0936a 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -15,7 +15,7 @@
#include "core/fxcrt/autorestorer.h"
#include "core/fxcrt/cfx_decimal.h"
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/locale_iface.h"
@@ -200,24 +200,22 @@ RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
FXCODEC_IMAGE_TYPE type = XFA_GetImageType(pImage->GetContentType());
ByteString bsContent;
- uint8_t* pImageBuffer = nullptr;
+ std::vector<uint8_t> buffer;
RetainPtr<IFX_SeekableReadStream> pImageFileRead;
if (wsImage.GetLength() > 0) {
XFA_AttributeEnum iEncoding = pImage->GetTransferEncoding();
if (iEncoding == XFA_AttributeEnum::Base64) {
ByteString bsData = wsImage.UTF8Encode();
- int32_t iLength = bsData.GetLength();
- pImageBuffer = FX_Alloc(uint8_t, iLength);
- int32_t iRead = XFA_Base64Decode(bsData.c_str(), pImageBuffer);
+ buffer.resize(bsData.GetLength());
+ int32_t iRead = XFA_Base64Decode(bsData.c_str(), buffer.data());
if (iRead > 0) {
pImageFileRead =
- pdfium::MakeRetain<CFX_MemoryStream>(pImageBuffer, iRead, false);
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(buffer.data(), iRead);
}
} else {
bsContent = wsImage.ToDefANSI();
- pImageFileRead = pdfium::MakeRetain<CFX_MemoryStream>(
- const_cast<uint8_t*>(bsContent.raw_str()), bsContent.GetLength(),
- false);
+ pImageFileRead = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ bsContent.raw_str(), bsContent.GetLength());
}
} else {
WideString wsURL = wsHref;
@@ -231,16 +229,15 @@ RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
}
pImageFileRead = pDoc->GetDocEnvironment()->OpenLinkedFile(pDoc, wsURL);
}
- if (!pImageFileRead) {
- FX_Free(pImageBuffer);
+ if (!pImageFileRead)
return nullptr;
- }
+
bNameImage = false;
RetainPtr<CFX_DIBitmap> pBitmap =
XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi);
- FX_Free(pImageBuffer);
return pBitmap;
}
+
bool SplitDateTime(const WideString& wsDateTime,
WideString& wsDate,
WideString& wsTime) {
diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp
index e4858e907e..2806a084d6 100644
--- a/xfa/fxfa/parser/cxfa_xmllocale.cpp
+++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp
@@ -8,7 +8,7 @@
#include <utility>
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
@@ -32,7 +32,7 @@ constexpr wchar_t kCurrencySymbol[] = L"currencySymbol";
std::unique_ptr<CXFA_XMLLocale> CXFA_XMLLocale::Create(
pdfium::span<uint8_t> data) {
auto stream =
- pdfium::MakeRetain<CFX_MemoryStream>(data.data(), data.size(), false);
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(data.data(), data.size());
CFX_XMLParser parser(stream);
auto doc = parser.Parse();
if (!doc)