From a169364e46956875db35fb1baacc4a0a1ee17f08 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 16 Aug 2017 13:56:12 -0400 Subject: Add parse depth limit to FormCalc parser Due to the recursive nature of the FormCalc parser, deeply nested expressions can lead to memory being exhausted. This check is being added to have the parser exit early instead of running out of memory. This should reduce the number of false positives about addressing issues being found by fuzzers. BUG=chromium:752433 Change-Id: I511ecfb07e32073555e1fd1658f3b8b47f1a5a91 Reviewed-on: https://pdfium-review.googlesource.com/11170 Commit-Queue: Ryan Harrison Reviewed-by: Tom Sepez --- xfa/fxfa/fm2js/cxfa_fmparser.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'xfa/fxfa/fm2js/cxfa_fmparser.h') diff --git a/xfa/fxfa/fm2js/cxfa_fmparser.h b/xfa/fxfa/fm2js/cxfa_fmparser.h index 66eb1f8392..ddfaa1aaa6 100644 --- a/xfa/fxfa/fm2js/cxfa_fmparser.h +++ b/xfa/fxfa/fm2js/cxfa_fmparser.h @@ -21,9 +21,14 @@ class CXFA_FMParser { std::unique_ptr Parse(); bool HasError() const; + void SetMaxParseDepthForTest(unsigned long max_depth) { + m_max_parse_depth = max_depth; + } + private: bool NextToken(); bool CheckThenNext(XFA_FM_TOKEN op); + bool IncrementParseDepthAndCheck(); std::vector> ParseTopExpression(); std::unique_ptr ParseFunction(); @@ -54,6 +59,8 @@ class CXFA_FMParser { std::unique_ptr m_lexer; std::unique_ptr m_token; bool m_error; + unsigned long m_parse_depth; + unsigned long m_max_parse_depth; }; #endif // XFA_FXFA_FM2JS_CXFA_FMPARSER_H_ -- cgit v1.2.3