From 1e19e25cd10c24f25beddff56b7c4b5fdc5adbcb Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Wed, 25 Oct 2017 14:32:14 -0400 Subject: Add in depth check for ToJavascript and related methods There exists a similar check for the parser, but it doesn't catch all cases of excessive memory usage, since a single parse step can generate multiple expressions that need to be converted or other cases where the parse depth doesn't match the emission depth later. Due to the expressions appearing in two different inheritence hierachies the depth information needs to be stored outside of the classes, thus the new depth class. Another way to handle this would be to change the method calls to take in a visitor object that tracks depth. This would require significant reworking of some of the code, so I am going to file a bug about doing that conversion as a cleanup. BUG=chromium:752495 Change-Id: Ica7c9b60ecf1e17530ea88b7bfb01582c63043be Reviewed-on: https://pdfium-review.googlesource.com/16752 Commit-Queue: Ryan Harrison Reviewed-by: Henrique Nakashima --- xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp') diff --git a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp index 192f935309..8582649fec 100644 --- a/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmparser_unittest.cpp @@ -10,6 +10,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/test_support.h" #include "third_party/base/ptr_util.h" +#include "xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h" TEST(CXFA_FMParserTest, Empty) { auto parser = pdfium::MakeUnique(L""); @@ -17,6 +18,7 @@ TEST(CXFA_FMParserTest, Empty) { ASSERT(ast != nullptr); EXPECT_FALSE(parser->HasError()); + CXFA_FMToJavaScriptDepth::Reset(); CFX_WideTextBuf buf; EXPECT_TRUE(ast->ToJavaScript(buf)); // TODO(dsinclair): This is a little weird ..... @@ -31,6 +33,7 @@ TEST(CXFA_FMParserTest, CommentOnlyIsError) { EXPECT_FALSE(parser->HasError()); // EXPECT_TRUE(parser->HasError()); + CXFA_FMToJavaScriptDepth::Reset(); CFX_WideTextBuf buf; EXPECT_TRUE(ast->ToJavaScript(buf)); EXPECT_EQ(L"// comments only", buf.AsStringView()); @@ -49,6 +52,7 @@ TEST(CXFA_FMParserTest, CommentThenValue) { ASSERT(ast != nullptr); EXPECT_FALSE(parser->HasError()); + CXFA_FMToJavaScriptDepth::Reset(); CFX_WideTextBuf buf; EXPECT_TRUE(ast->ToJavaScript(buf)); EXPECT_EQ(ret, buf.AsStringView()); @@ -104,6 +108,7 @@ TEST(CXFA_FMParserTest, Parse) { ASSERT(ast != nullptr); EXPECT_FALSE(parser->HasError()); + CXFA_FMToJavaScriptDepth::Reset(); CFX_WideTextBuf buf; EXPECT_TRUE(ast->ToJavaScript(buf)); EXPECT_EQ(ret, buf.AsStringView()); -- cgit v1.2.3