diff options
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fde/xml/cfde_xmlparser.cpp | 3 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlsyntaxparser.cpp | 28 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlsyntaxparser.h | 4 | ||||
-rw-r--r-- | xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp | 45 |
4 files changed, 27 insertions, 53 deletions
diff --git a/xfa/fde/xml/cfde_xmlparser.cpp b/xfa/fde/xml/cfde_xmlparser.cpp index f4d2a0f113..5b8993de1b 100644 --- a/xfa/fde/xml/cfde_xmlparser.cpp +++ b/xfa/fde/xml/cfde_xmlparser.cpp @@ -20,13 +20,12 @@ CFDE_XMLParser::CFDE_XMLParser(CFDE_XMLNode* pParent, m_dwCheckStatus(0), m_dwCurrentCheckStatus(0), m_pStream(pStream), - m_pParser(pdfium::MakeUnique<CFDE_XMLSyntaxParser>()), + m_pParser(pdfium::MakeUnique<CFDE_XMLSyntaxParser>(m_pStream)), m_pParent(pParent), m_pChild(nullptr), m_syntaxParserResult(FDE_XmlSyntaxResult::None) { ASSERT(m_pParent && m_pStream); m_NodeStack.push(m_pParent); - m_pParser->Init(m_pStream, 32 * 1024); } CFDE_XMLParser::~CFDE_XMLParser() {} diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser.cpp index 93f8f1d51f..ea4af42f9e 100644 --- a/xfa/fde/xml/cfde_xmlsyntaxparser.cpp +++ b/xfa/fde/xml/cfde_xmlsyntaxparser.cpp @@ -77,9 +77,10 @@ int32_t GetUTF8EncodeLength(const wchar_t* pSrc, int32_t iSrcLen) { } // namespace -CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() - : m_pStream(nullptr), - m_iXMLPlaneSize(-1), +CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser( + const CFX_RetainPtr<IFGAS_Stream>& pStream) + : m_pStream(pStream), + m_iXMLPlaneSize(32 * 1024), m_iCurrentPos(0), m_iCurrentNodeNum(-1), m_iLastNodeNum(-1), @@ -99,21 +100,15 @@ CFDE_XMLSyntaxParser::CFDE_XMLSyntaxParser() m_syntaxParserState(FDE_XmlSyntaxState::Text), m_wQuotationMark(0), m_iEntityStart(-1) { + ASSERT(pStream); + m_CurNode.iNodeNum = -1; m_CurNode.eNodeType = FDE_XMLNODE_Unknown; -} -void CFDE_XMLSyntaxParser::Init(const CFX_RetainPtr<IFGAS_Stream>& pStream, - int32_t iXMLPlaneSize) { - ASSERT(!m_pStream && !m_pBuffer); - ASSERT(pStream && iXMLPlaneSize > 0); - int32_t iStreamLength = pStream->GetLength(); - ASSERT(iStreamLength > 0); - m_pStream = pStream; - m_iXMLPlaneSize = std::min(iXMLPlaneSize, iStreamLength); + m_iXMLPlaneSize = std::min(m_iXMLPlaneSize, m_pStream->GetLength()); + uint8_t bom[4]; m_iCurrentPos = m_pStream->GetBOM(bom); - ASSERT(!m_pBuffer); FX_SAFE_INT32 alloc_size_safe = m_iXMLPlaneSize; alloc_size_safe += 1; // For NUL. @@ -124,14 +119,12 @@ void CFDE_XMLSyntaxParser::Init(const CFX_RetainPtr<IFGAS_Stream>& pStream, m_pBuffer = FX_Alloc( wchar_t, pdfium::base::ValueOrDieForType<size_t>(alloc_size_safe)); - m_pStart = m_pEnd = m_pBuffer; + m_pStart = m_pBuffer; + m_pEnd = m_pBuffer; - ASSERT(!m_BlockBuffer.IsInitialized()); m_BlockBuffer.InitBuffer(); std::tie(m_pCurrentBlock, m_iIndexInBlock) = m_BlockBuffer.GetAvailableBlock(); - m_iParsedBytes = m_iParsedChars = 0; - m_iBufferChars = 0; } FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { @@ -600,7 +593,6 @@ FDE_XmlSyntaxResult CFDE_XMLSyntaxParser::DoSyntaxParse() { } CFDE_XMLSyntaxParser::~CFDE_XMLSyntaxParser() { - m_pCurrentBlock = nullptr; FX_Free(m_pBuffer); } diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser.h b/xfa/fde/xml/cfde_xmlsyntaxparser.h index 9140a8345f..ef2cd275bd 100644 --- a/xfa/fde/xml/cfde_xmlsyntaxparser.h +++ b/xfa/fde/xml/cfde_xmlsyntaxparser.h @@ -35,11 +35,9 @@ enum class FDE_XmlSyntaxResult { class CFDE_XMLSyntaxParser { public: - CFDE_XMLSyntaxParser(); + explicit CFDE_XMLSyntaxParser(const CFX_RetainPtr<IFGAS_Stream>& pStream); ~CFDE_XMLSyntaxParser(); - void Init(const CFX_RetainPtr<IFGAS_Stream>& pStream, int32_t iXMLPlaneSize); - FDE_XmlSyntaxResult DoSyntaxParse(); int32_t GetStatus() const; diff --git a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp index e7e6894820..e54b2cecaf 100644 --- a/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp +++ b/xfa/fde/xml/cfde_xmlsyntaxparser_unittest.cpp @@ -28,8 +28,7 @@ TEST(CFDE_XMLSyntaxParser, CData) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -76,8 +75,7 @@ TEST(CFDE_XMLSyntaxParser, CDataWithInnerScript) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -113,8 +111,7 @@ TEST(CFDE_XMLSyntaxParser, ArrowBangArrow) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); @@ -148,8 +145,7 @@ TEST(CFDE_XMLSyntaxParser, ArrowBangBracketArrow) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -178,8 +174,7 @@ TEST(CFDE_XMLSyntaxParser, IncompleteCData) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -208,8 +203,7 @@ TEST(CFDE_XMLSyntaxParser, UnClosedCData) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -238,8 +232,7 @@ TEST(CFDE_XMLSyntaxParser, EmptyCData) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -275,8 +268,7 @@ TEST(CFDE_XMLSyntaxParser, Comment) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -309,8 +301,7 @@ TEST(CFDE_XMLSyntaxParser, IncorrectCommentStart) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -343,8 +334,7 @@ TEST(CFDE_XMLSyntaxParser, CommentEmpty) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -377,8 +367,7 @@ TEST(CFDE_XMLSyntaxParser, CommentThreeDash) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -405,8 +394,7 @@ TEST(CFDE_XMLSyntaxParser, CommentTwoDash) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -437,8 +425,7 @@ TEST(CFDE_XMLSyntaxParser, Entities) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -469,8 +456,7 @@ TEST(CFDE_XMLSyntaxParser, EntityOverflowHex) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); @@ -501,8 +487,7 @@ TEST(CFDE_XMLSyntaxParser, EntityOverflowDecimal) { size_t len = FXSYS_wcslen(input) * sizeof(wchar_t); CFX_RetainPtr<IFGAS_Stream> stream = IFGAS_Stream::CreateStream( reinterpret_cast<uint8_t*>(const_cast<wchar_t*>(input)), len, 0); - CFDE_XMLSyntaxParser parser; - parser.Init(stream, 256); + CFDE_XMLSyntaxParser parser(stream); EXPECT_EQ(FDE_XmlSyntaxResult::ElementOpen, parser.DoSyntaxParse()); EXPECT_EQ(FDE_XmlSyntaxResult::TagName, parser.DoSyntaxParse()); EXPECT_EQ(L"script", parser.GetTagName()); |