From ba367068887aca9f700289aa1b8c198920ca39a2 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 1 May 2018 17:02:54 +0000 Subject: Fixes XML Instruction handling in CXFA_DocumentParser. This CL fixes issues with handling XML instructions in CXFA_DocumentParser. Unittests were added to verify the behaviour. Change-Id: Iff8d51d0e6d411419473c9b2c32c700d4bbf86f5 Reviewed-on: https://pdfium-review.googlesource.com/31810 Commit-Queue: dsinclair Reviewed-by: Ryan Harrison Reviewed-by: Henrique Nakashima --- xfa/fxfa/parser/cxfa_document.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'xfa/fxfa/parser/cxfa_document.cpp') diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index 6860c83376..9e5143c5a4 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -1447,17 +1447,19 @@ CFXJSE_Engine* CXFA_Document::GetScriptContext() const { XFA_VERSION CXFA_Document::RecognizeXFAVersionNumber( const WideString& wsTemplateNS) { WideStringView wsTemplateURIPrefix(kTemplateNS); - size_t nPrefixLength = wsTemplateURIPrefix.GetLength(); - if (WideStringView(wsTemplateNS.c_str(), wsTemplateNS.GetLength()) != - wsTemplateURIPrefix) { + if (wsTemplateNS.GetLength() <= wsTemplateURIPrefix.GetLength()) return XFA_VERSION_UNKNOWN; - } - auto nDotPos = wsTemplateNS.Find('.', nPrefixLength); + + size_t prefixLength = wsTemplateURIPrefix.GetLength(); + if (WideStringView(wsTemplateNS.c_str(), prefixLength) != wsTemplateURIPrefix) + return XFA_VERSION_UNKNOWN; + + auto nDotPos = wsTemplateNS.Find('.', prefixLength); if (!nDotPos.has_value()) return XFA_VERSION_UNKNOWN; int8_t iMajor = FXSYS_wtoi( - wsTemplateNS.Mid(nPrefixLength, nDotPos.value() - nPrefixLength).c_str()); + wsTemplateNS.Mid(prefixLength, nDotPos.value() - prefixLength).c_str()); int8_t iMinor = FXSYS_wtoi(wsTemplateNS .Mid(nDotPos.value() + 1, -- cgit v1.2.3