summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmparser.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-05-08 15:20:27 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-05-08 15:20:27 +0000
commitdec08c8d3fbc4e89748f2d655b32727cfab373ed (patch)
tree9aac943ee5b8471322be5747d02ed8927a5ffa05 /xfa/fxfa/fm2js/cxfa_fmparser.cpp
parentbda113c645673fd152bb9ca3eaddd3c34920223e (diff)
downloadpdfium-dec08c8d3fbc4e89748f2d655b32727cfab373ed.tar.xz
[fm2js] Fail transpiling if lexer has left over data
If there is remaining data after the lexer has said it's complete then something has gone wrong while lexing the formcalc data. This CL changes the transpiler to return an error in the case of the lexer havign extra data. Bug: chromium:834575 Change-Id: I8a1288a7f01cc69faf2033829d68246d815258de Reviewed-on: https://pdfium-review.googlesource.com/32130 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmparser.cpp')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmparser.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmparser.cpp b/xfa/fxfa/fm2js/cxfa_fmparser.cpp
index fb4a7f4cf9..be0a31b519 100644
--- a/xfa/fxfa/fm2js/cxfa_fmparser.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmparser.cpp
@@ -21,18 +21,26 @@ constexpr unsigned int kMaxPostExpressions = 256;
} // namespace
CXFA_FMParser::CXFA_FMParser(const WideStringView& wsFormcalc)
- : m_error(false), m_parse_depth(0), m_max_parse_depth(kMaxParseDepth) {
- m_lexer = pdfium::MakeUnique<CXFA_FMLexer>(wsFormcalc);
- m_token = m_lexer->NextToken();
-}
+ : m_lexer(pdfium::MakeUnique<CXFA_FMLexer>(wsFormcalc)),
+ m_error(false),
+ m_parse_depth(0),
+ m_max_parse_depth(kMaxParseDepth) {}
-CXFA_FMParser::~CXFA_FMParser() {}
+CXFA_FMParser::~CXFA_FMParser() = default;
std::unique_ptr<CXFA_FMAST> CXFA_FMParser::Parse() {
+ m_token = m_lexer->NextToken();
+ if (HasError())
+ return nullptr;
+
auto expressions = ParseExpressionList();
if (HasError())
return nullptr;
+ // We failed to parse all of the input so something has gone wrong.
+ if (!m_lexer->IsComplete())
+ return nullptr;
+
return pdfium::MakeUnique<CXFA_FMAST>(std::move(expressions));
}
@@ -66,6 +74,7 @@ CXFA_FMParser::ParseExpressionList() {
AutoRestorer<unsigned long> restorer(&m_parse_depth);
if (HasError() || !IncrementParseDepthAndCheck())
return std::vector<std::unique_ptr<CXFA_FMExpression>>();
+
std::vector<std::unique_ptr<CXFA_FMExpression>> expressions;
while (!HasError()) {
if (m_token.m_type == TOKeof || m_token.m_type == TOKendfunc ||