summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-04-12 13:29:37 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-04-12 17:52:56 +0000
commit51114964fdb2a98f763318ce9affca906ed079e3 (patch)
tree0b5499f30ab34cd1f4f37b5368a766e57eca678a
parent661fcc0156b78fd40937c0844034605f430b94c6 (diff)
downloadpdfium-51114964fdb2a98f763318ce9affca906ed079e3.tar.xz
Fold CXFA_WideTextRead into IFGAS_Stream
This Cl moves CXFA_WideTextRead to be in the anonymous namespace of IFGAS_Stream and adds a IFGAS_Stream::CreateWideStringReadStream() method. This is done so we have all the implementations of IFGAS_Stream centralized. Change-Id: I9fbbf0a493fc2dd05fcd544e344268214a75d8a1 Reviewed-on: https://pdfium-review.googlesource.com/4052 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
-rw-r--r--BUILD.gn2
-rw-r--r--testing/libfuzzer/pdf_cfx_saxreader_fuzzer.cc1
-rw-r--r--testing/libfuzzer/pdf_css_fuzzer.cc1
-rw-r--r--testing/libfuzzer/pdf_xml_fuzzer.cc5
-rw-r--r--xfa/fgas/crt/ifgas_stream.cpp129
-rw-r--r--xfa/fgas/crt/ifgas_stream.h2
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp5
-rw-r--r--xfa/fxfa/parser/cxfa_widetextread.cpp96
-rw-r--r--xfa/fxfa/parser/cxfa_widetextread.h44
9 files changed, 133 insertions, 152 deletions
diff --git a/BUILD.gn b/BUILD.gn
index c279a6c831..1d8f3530ec 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1790,8 +1790,6 @@ if (pdf_enable_xfa) {
"xfa/fxfa/parser/cxfa_value.h",
"xfa/fxfa/parser/cxfa_valuearray.cpp",
"xfa/fxfa/parser/cxfa_valuearray.h",
- "xfa/fxfa/parser/cxfa_widetextread.cpp",
- "xfa/fxfa/parser/cxfa_widetextread.h",
"xfa/fxfa/parser/cxfa_widgetdata.cpp",
"xfa/fxfa/parser/cxfa_widgetdata.h",
"xfa/fxfa/parser/cxfa_xmllocale.cpp",
diff --git a/testing/libfuzzer/pdf_cfx_saxreader_fuzzer.cc b/testing/libfuzzer/pdf_cfx_saxreader_fuzzer.cc
index 0dfbbdf639..31e24e82f2 100644
--- a/testing/libfuzzer/pdf_cfx_saxreader_fuzzer.cc
+++ b/testing/libfuzzer/pdf_cfx_saxreader_fuzzer.cc
@@ -7,7 +7,6 @@
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/xml/cfx_saxreader.h"
#include "xfa/fgas/crt/ifgas_stream.h"
-#include "xfa/fxfa/parser/cxfa_widetextread.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
CFX_SAXReader reader;
diff --git a/testing/libfuzzer/pdf_css_fuzzer.cc b/testing/libfuzzer/pdf_css_fuzzer.cc
index 7566bb1ca2..9f5cdfec45 100644
--- a/testing/libfuzzer/pdf_css_fuzzer.cc
+++ b/testing/libfuzzer/pdf_css_fuzzer.cc
@@ -9,7 +9,6 @@
#include "xfa/fde/css/cfde_csssyntaxparser.h"
#include "xfa/fde/css/fde_css.h"
#include "xfa/fgas/crt/ifgas_stream.h"
-#include "xfa/fxfa/parser/cxfa_widetextread.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
CFX_WideString input = CFX_WideString::FromUTF8(
diff --git a/testing/libfuzzer/pdf_xml_fuzzer.cc b/testing/libfuzzer/pdf_xml_fuzzer.cc
index 13eda60d77..8284bc6ce7 100644
--- a/testing/libfuzzer/pdf_xml_fuzzer.cc
+++ b/testing/libfuzzer/pdf_xml_fuzzer.cc
@@ -13,7 +13,7 @@
#include "xfa/fde/xml/cfde_xmldoc.h"
#include "xfa/fde/xml/cfde_xmlnode.h"
#include "xfa/fde/xml/cfde_xmlparser.h"
-#include "xfa/fxfa/parser/cxfa_widetextread.h"
+#include "xfa/fgas/crt/ifgas_stream.h"
namespace {
@@ -53,7 +53,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
CFX_WideString input =
CFX_WideString::FromUTF8(CFX_ByteStringC(data, safe_size.ValueOrDie()));
- auto stream = pdfium::MakeRetain<CXFA_WideTextRead>(input);
+ CFX_RetainPtr<IFGAS_Stream> stream =
+ IFGAS_Stream::CreateWideStringReadStream(input);
if (!stream)
return 0;
diff --git a/xfa/fgas/crt/ifgas_stream.cpp b/xfa/fgas/crt/ifgas_stream.cpp
index dcd13b162e..f36ebb556b 100644
--- a/xfa/fgas/crt/ifgas_stream.cpp
+++ b/xfa/fgas/crt/ifgas_stream.cpp
@@ -15,7 +15,9 @@
#include <memory>
#include <utility>
+#include "core/fxcrt/fx_ext.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#include "xfa/fgas/crt/fgas_codepage.h"
namespace {
@@ -67,7 +69,7 @@ class CFGAS_FileReadStreamImp : public IFGAS_StreamImp {
void Flush() override {}
bool SetLength(int32_t iLength) override { return false; }
- protected:
+ private:
CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead;
int32_t m_iPosition;
int32_t m_iLength;
@@ -95,7 +97,7 @@ class CFGAS_FileWriteStreamImp : public IFGAS_StreamImp {
void Flush() override;
bool SetLength(int32_t iLength) override { return false; }
- protected:
+ private:
CFX_RetainPtr<IFX_SeekableWriteStream> m_pFileWrite;
int32_t m_iPosition;
};
@@ -121,7 +123,7 @@ class CFGAS_Stream : public IFGAS_Stream {
uint16_t GetCodePage() const override;
uint16_t SetCodePage(uint16_t wCodePage) override;
- protected:
+ private:
CFGAS_Stream(std::unique_ptr<IFGAS_StreamImp> imp, uint32_t dwAccess);
~CFGAS_Stream() override;
@@ -155,7 +157,7 @@ class CFGAS_TextStream : public IFGAS_Stream {
uint16_t GetCodePage() const override;
uint16_t SetCodePage(uint16_t wCodePage) override;
- protected:
+ private:
explicit CFGAS_TextStream(const CFX_RetainPtr<IFGAS_Stream>& pStream);
~CFGAS_TextStream() override;
@@ -169,6 +171,35 @@ class CFGAS_TextStream : public IFGAS_Stream {
CFX_RetainPtr<IFGAS_Stream> m_pStreamImp;
};
+class CFGAS_WideStringReadStream : public IFGAS_Stream {
+ public:
+ template <typename T, typename... Args>
+ friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
+
+ // IFGAS_Stream
+ uint32_t GetAccessModes() const override;
+ int32_t GetLength() const override;
+ int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
+ int32_t GetPosition() override;
+ bool IsEOF() const override;
+ int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t ReadString(wchar_t* pStr, int32_t iMaxLength, bool& bEOS) override;
+ int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
+ int32_t WriteString(const wchar_t* pStr, int32_t iLength) override;
+ void Flush() override {}
+ bool SetLength(int32_t iLength) override;
+ int32_t GetBOM(uint8_t bom[4]) const override;
+ uint16_t GetCodePage() const override;
+ uint16_t SetCodePage(uint16_t wCodePage) override;
+
+ private:
+ explicit CFGAS_WideStringReadStream(const CFX_WideString& wsBuffer);
+ ~CFGAS_WideStringReadStream() override;
+
+ CFX_WideString m_wsBuffer;
+ int32_t m_iPosition;
+};
+
IFGAS_StreamImp::IFGAS_StreamImp() : m_dwAccess(0) {}
CFGAS_FileReadStreamImp::CFGAS_FileReadStreamImp()
@@ -186,6 +217,7 @@ bool CFGAS_FileReadStreamImp::LoadFileRead(
int32_t CFGAS_FileReadStreamImp::GetLength() const {
return m_iLength;
}
+
int32_t CFGAS_FileReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
switch (eSeek) {
case FX_STREAMSEEK_Begin:
@@ -205,6 +237,7 @@ int32_t CFGAS_FileReadStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
}
return m_iPosition;
}
+
bool CFGAS_FileReadStreamImp::IsEOF() const {
return m_iPosition >= m_iLength;
}
@@ -650,6 +683,88 @@ uint16_t CFGAS_Stream::SetCodePage(uint16_t wCodePage) {
#endif
}
+CFGAS_WideStringReadStream::CFGAS_WideStringReadStream(
+ const CFX_WideString& wsBuffer)
+ : m_wsBuffer(wsBuffer), m_iPosition(0) {}
+
+CFGAS_WideStringReadStream::~CFGAS_WideStringReadStream() {}
+
+uint32_t CFGAS_WideStringReadStream::GetAccessModes() const {
+ return 0;
+}
+
+int32_t CFGAS_WideStringReadStream::GetLength() const {
+ return m_wsBuffer.GetLength() * sizeof(wchar_t);
+}
+
+int32_t CFGAS_WideStringReadStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
+ switch (eSeek) {
+ case FX_STREAMSEEK_Begin:
+ m_iPosition = iOffset;
+ break;
+ case FX_STREAMSEEK_Current:
+ m_iPosition += iOffset;
+ break;
+ case FX_STREAMSEEK_End:
+ m_iPosition = m_wsBuffer.GetLength() + iOffset;
+ break;
+ }
+ m_iPosition = pdfium::clamp(0, m_iPosition, m_wsBuffer.GetLength());
+ return GetPosition();
+}
+
+int32_t CFGAS_WideStringReadStream::GetPosition() {
+ return m_iPosition * sizeof(wchar_t);
+}
+
+bool CFGAS_WideStringReadStream::IsEOF() const {
+ return m_iPosition >= m_wsBuffer.GetLength();
+}
+
+int32_t CFGAS_WideStringReadStream::ReadData(uint8_t* pBuffer,
+ int32_t iBufferSize) {
+ return 0;
+}
+
+int32_t CFGAS_WideStringReadStream::ReadString(wchar_t* pStr,
+ int32_t iMaxLength,
+ bool& bEOS) {
+ iMaxLength = std::min(iMaxLength, m_wsBuffer.GetLength() - m_iPosition);
+ if (iMaxLength == 0)
+ return 0;
+
+ FXSYS_wcsncpy(pStr, m_wsBuffer.c_str() + m_iPosition, iMaxLength);
+ m_iPosition += iMaxLength;
+ bEOS = IsEOF();
+ return iMaxLength;
+}
+
+int32_t CFGAS_WideStringReadStream::WriteData(const uint8_t* pBuffer,
+ int32_t iBufferSize) {
+ return 0;
+}
+
+int32_t CFGAS_WideStringReadStream::WriteString(const wchar_t* pStr,
+ int32_t iLength) {
+ return 0;
+}
+
+bool CFGAS_WideStringReadStream::SetLength(int32_t iLength) {
+ return false;
+}
+
+int32_t CFGAS_WideStringReadStream::GetBOM(uint8_t bom[4]) const {
+ return 0;
+}
+
+uint16_t CFGAS_WideStringReadStream::GetCodePage() const {
+ return (sizeof(wchar_t) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE;
+}
+
+uint16_t CFGAS_WideStringReadStream::SetCodePage(uint16_t wCodePage) {
+ return GetCodePage();
+}
+
} // namespace
// static
@@ -684,3 +799,9 @@ CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateWriteStream(
return pdfium::MakeRetain<CFGAS_TextStream>(
pdfium::MakeRetain<CFGAS_Stream>(std::move(pImp), FX_STREAMACCESS_Write));
}
+
+// static
+CFX_RetainPtr<IFGAS_Stream> IFGAS_Stream::CreateWideStringReadStream(
+ const CFX_WideString& buffer) {
+ return pdfium::MakeRetain<CFGAS_WideStringReadStream>(buffer);
+}
diff --git a/xfa/fgas/crt/ifgas_stream.h b/xfa/fgas/crt/ifgas_stream.h
index d8efc41afd..df9d93afa3 100644
--- a/xfa/fgas/crt/ifgas_stream.h
+++ b/xfa/fgas/crt/ifgas_stream.h
@@ -27,6 +27,8 @@ class IFGAS_Stream : public CFX_Retainable {
const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead);
static CFX_RetainPtr<IFGAS_Stream> CreateWriteStream(
const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite);
+ static CFX_RetainPtr<IFGAS_Stream> CreateWideStringReadStream(
+ const CFX_WideString& buffer);
virtual uint32_t GetAccessModes() const = 0;
virtual int32_t GetLength() const = 0;
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index d423bba56d..cce4b68a27 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -20,10 +20,10 @@
#include "xfa/fde/xml/cfde_xmlparser.h"
#include "xfa/fde/xml/cfde_xmltext.h"
#include "xfa/fgas/crt/fgas_codepage.h"
+#include "xfa/fgas/crt/ifgas_stream.h"
#include "xfa/fxfa/fxfa.h"
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_node.h"
-#include "xfa/fxfa/parser/cxfa_widetextread.h"
#include "xfa/fxfa/parser/xfa_basic_data.h"
#include "xfa/fxfa/parser/xfa_utils.h"
@@ -323,7 +323,8 @@ int32_t CXFA_SimpleParser::ParseXMLData(const CFX_WideString& wsXML,
CloseParser();
pXMLNode = nullptr;
m_pXMLDoc = pdfium::MakeUnique<CFDE_XMLDoc>();
- auto pStream = pdfium::MakeRetain<CXFA_WideTextRead>(wsXML);
+ CFX_RetainPtr<IFGAS_Stream> pStream =
+ IFGAS_Stream::CreateWideStringReadStream(wsXML);
auto pParser =
pdfium::MakeUnique<CFDE_XMLParser>(m_pXMLDoc->GetRoot(), pStream);
pParser->m_dwCheckStatus = 0x03;
diff --git a/xfa/fxfa/parser/cxfa_widetextread.cpp b/xfa/fxfa/parser/cxfa_widetextread.cpp
deleted file mode 100644
index dc210d1828..0000000000
--- a/xfa/fxfa/parser/cxfa_widetextread.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fxfa/parser/cxfa_widetextread.h"
-
-#include <algorithm>
-
-#include "core/fxcrt/fx_ext.h"
-#include "third_party/base/stl_util.h"
-#include "xfa/fgas/crt/fgas_codepage.h"
-
-CXFA_WideTextRead::CXFA_WideTextRead(const CFX_WideString& wsBuffer)
- : m_wsBuffer(wsBuffer), m_iPosition(0) {}
-
-CXFA_WideTextRead::~CXFA_WideTextRead() {}
-
-uint32_t CXFA_WideTextRead::GetAccessModes() const {
- return 0;
-}
-
-int32_t CXFA_WideTextRead::GetLength() const {
- return m_wsBuffer.GetLength() * sizeof(wchar_t);
-}
-
-int32_t CXFA_WideTextRead::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) {
- switch (eSeek) {
- case FX_STREAMSEEK_Begin:
- m_iPosition = iOffset;
- break;
- case FX_STREAMSEEK_Current:
- m_iPosition += iOffset;
- break;
- case FX_STREAMSEEK_End:
- m_iPosition = m_wsBuffer.GetLength() + iOffset;
- break;
- }
- m_iPosition = pdfium::clamp(0, m_iPosition, m_wsBuffer.GetLength());
- return GetPosition();
-}
-
-int32_t CXFA_WideTextRead::GetPosition() {
- return m_iPosition * sizeof(wchar_t);
-}
-
-bool CXFA_WideTextRead::IsEOF() const {
- return m_iPosition >= m_wsBuffer.GetLength();
-}
-
-int32_t CXFA_WideTextRead::ReadData(uint8_t* pBuffer, int32_t iBufferSize) {
- return 0;
-}
-
-int32_t CXFA_WideTextRead::ReadString(wchar_t* pStr,
- int32_t iMaxLength,
- bool& bEOS) {
- iMaxLength = std::min(iMaxLength, m_wsBuffer.GetLength() - m_iPosition);
- if (iMaxLength == 0)
- return 0;
-
- FXSYS_wcsncpy(pStr, m_wsBuffer.c_str() + m_iPosition, iMaxLength);
- m_iPosition += iMaxLength;
- bEOS = IsEOF();
- return iMaxLength;
-}
-
-int32_t CXFA_WideTextRead::WriteData(const uint8_t* pBuffer,
- int32_t iBufferSize) {
- return 0;
-}
-
-int32_t CXFA_WideTextRead::WriteString(const wchar_t* pStr, int32_t iLength) {
- return 0;
-}
-
-bool CXFA_WideTextRead::SetLength(int32_t iLength) {
- return false;
-}
-
-int32_t CXFA_WideTextRead::GetBOM(uint8_t bom[4]) const {
- return 0;
-}
-
-uint16_t CXFA_WideTextRead::GetCodePage() const {
- return (sizeof(wchar_t) == 2) ? FX_CODEPAGE_UTF16LE : FX_CODEPAGE_UTF32LE;
-}
-
-uint16_t CXFA_WideTextRead::SetCodePage(uint16_t wCodePage) {
- return GetCodePage();
-}
-
-CFX_WideString CXFA_WideTextRead::GetSrcText() const {
- return m_wsBuffer;
-}
diff --git a/xfa/fxfa/parser/cxfa_widetextread.h b/xfa/fxfa/parser/cxfa_widetextread.h
deleted file mode 100644
index 648e14ed0d..0000000000
--- a/xfa/fxfa/parser/cxfa_widetextread.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FXFA_PARSER_CXFA_WIDETEXTREAD_H_
-#define XFA_FXFA_PARSER_CXFA_WIDETEXTREAD_H_
-
-#include "core/fxcrt/cfx_retain_ptr.h"
-#include "xfa/fgas/crt/ifgas_stream.h"
-
-class CXFA_WideTextRead : public IFGAS_Stream {
- public:
- template <typename T, typename... Args>
- friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args);
-
- // IFGAS_Stream
- uint32_t GetAccessModes() const override;
- int32_t GetLength() const override;
- int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) override;
- int32_t GetPosition() override;
- bool IsEOF() const override;
- int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) override;
- int32_t ReadString(wchar_t* pStr, int32_t iMaxLength, bool& bEOS) override;
- int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) override;
- int32_t WriteString(const wchar_t* pStr, int32_t iLength) override;
- void Flush() override {}
- bool SetLength(int32_t iLength) override;
- int32_t GetBOM(uint8_t bom[4]) const override;
- uint16_t GetCodePage() const override;
- uint16_t SetCodePage(uint16_t wCodePage) override;
-
- CFX_WideString GetSrcText() const;
-
- private:
- explicit CXFA_WideTextRead(const CFX_WideString& wsBuffer);
- ~CXFA_WideTextRead() override;
-
- CFX_WideString m_wsBuffer;
- int32_t m_iPosition;
-};
-
-#endif // XFA_FXFA_PARSER_CXFA_WIDETEXTREAD_H_