From dec08c8d3fbc4e89748f2d655b32727cfab373ed Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 8 May 2018 15:20:27 +0000 Subject: [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 Reviewed-by: Henrique Nakashima --- xfa/fxfa/fm2js/cxfa_fmparser.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'xfa/fxfa/fm2js/cxfa_fmparser.cpp') 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(wsFormcalc); - m_token = m_lexer->NextToken(); -} + : m_lexer(pdfium::MakeUnique(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_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(std::move(expressions)); } @@ -66,6 +74,7 @@ CXFA_FMParser::ParseExpressionList() { AutoRestorer restorer(&m_parse_depth); if (HasError() || !IncrementParseDepthAndCheck()) return std::vector>(); + std::vector> expressions; while (!HasError()) { if (m_token.m_type == TOKeof || m_token.m_type == TOKendfunc || -- cgit v1.2.3