diff options
author | Ryan Harrison <rharrison@chromium.org> | 2017-10-26 11:00:51 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-26 15:16:56 +0000 |
commit | efc879d226e98ddad36704d78f52037ccf4369dc (patch) | |
tree | 50e4510a0ff984d339b08a7a5ea4a26fa90926db /xfa/fxfa/fm2js/cxfa_fmexpression.cpp | |
parent | 78b334a824c42138f5e98060638b1643b0279602 (diff) | |
download | pdfium-efc879d226e98ddad36704d78f52037ccf4369dc.tar.xz |
Consistently apply JS size check
This CL makes the use of CXFA_IsTooBig consistent and universal across
all of the ToJavascript and related methods. Previously this method
was only applied in some calls. It is now being tested as a
precondition and postcondition on every call and as a post condition
for the entire translation process.
There are some size checks within methods that potentially generate
large amounts of JS that have been left in.
BUG=chromium:752920
Change-Id: I1a8bfe21e0a17c2e47592fc6017060243674f1bc
Reviewed-on: https://pdfium-review.googlesource.com/16812
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmexpression.cpp')
-rw-r--r-- | xfa/fxfa/fm2js/cxfa_fmexpression.cpp | 99 |
1 files changed, 46 insertions, 53 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp index 661ce42789..759a875b8d 100644 --- a/xfa/fxfa/fm2js/cxfa_fmexpression.cpp +++ b/xfa/fxfa/fm2js/cxfa_fmexpression.cpp @@ -9,6 +9,7 @@ #include <utility> #include "core/fxcrt/cfx_widetextbuf.h" +#include "xfa/fxfa/fm2js/cxfa_fmsimpleexpression.h" #include "xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h" namespace { @@ -32,12 +33,12 @@ CXFA_FMExpression::CXFA_FMExpression(uint32_t line, XFA_FM_EXPTYPE type) bool CXFA_FMExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - return depthManager.IsWithinMaxDepth(); + return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth(); } bool CXFA_FMExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - return depthManager.IsWithinMaxDepth(); + return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth(); } CXFA_FMFunctionDefinition::CXFA_FMFunctionDefinition( @@ -56,12 +57,12 @@ CXFA_FMFunctionDefinition::~CXFA_FMFunctionDefinition() {} bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; if (m_isGlobal && m_pExpressions.empty()) { javascript << L"// comments only"; - return true; + return !CXFA_IsTooBig(javascript); } if (m_isGlobal) { javascript << L"(\n"; @@ -98,7 +99,8 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { ret = expr->ToImpliedReturnJS(javascript); else ret = expr->ToJavaScript(javascript); - if (!ret || CXFA_IsTooBig(javascript)) + + if (!ret) return false; } javascript << L"return "; @@ -114,12 +116,12 @@ bool CXFA_FMFunctionDefinition::ToJavaScript(CFX_WideTextBuf& javascript) { if (m_isGlobal) { javascript << L").call(this);\n"; } - return true; + return !CXFA_IsTooBig(javascript); } -bool CXFA_FMFunctionDefinition::ToImpliedReturnJS(CFX_WideTextBuf&) { +bool CXFA_FMFunctionDefinition::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - return depthManager.IsWithinMaxDepth(); + return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth(); } CXFA_FMVarExpression::CXFA_FMVarExpression( @@ -134,7 +136,7 @@ CXFA_FMVarExpression::~CXFA_FMVarExpression() {} bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"var "; @@ -157,12 +159,12 @@ bool CXFA_FMVarExpression::ToJavaScript(CFX_WideTextBuf& javascript) { } else { javascript << L"\"\";\n"; } - return true; + return !CXFA_IsTooBig(javascript); } bool CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"var "; @@ -189,7 +191,7 @@ bool CXFA_FMVarExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { javascript << L" = "; javascript << tempName; javascript << L";\n"; - return true; + return !CXFA_IsTooBig(javascript); } CXFA_FMExpExpression::CXFA_FMExpExpression( @@ -202,7 +204,7 @@ CXFA_FMExpExpression::~CXFA_FMExpExpression() {} bool CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; bool ret = m_pExpression->ToJavaScript(javascript); @@ -213,7 +215,7 @@ bool CXFA_FMExpExpression::ToJavaScript(CFX_WideTextBuf& javascript) { bool CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; if (m_pExpression->GetOperatorToken() == TOKassign) @@ -231,7 +233,7 @@ bool CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { if (!m_pExpression->ToJavaScript(javascript)) return false; javascript << L");\n"; - return true; + return !CXFA_IsTooBig(javascript); } javascript << RUNTIMEFUNCTIONRETURNVALUE; @@ -239,7 +241,7 @@ bool CXFA_FMExpExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { if (!m_pExpression->ToJavaScript(javascript)) return false; javascript << L";\n"; - return true; + return !CXFA_IsTooBig(javascript); } CXFA_FMBlockExpression::CXFA_FMBlockExpression( @@ -252,21 +254,21 @@ CXFA_FMBlockExpression::~CXFA_FMBlockExpression() {} bool CXFA_FMBlockExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"{\n"; for (const auto& expr : m_ExpressionList) { - if (!expr->ToJavaScript(javascript) || CXFA_IsTooBig(javascript)) + if (!expr->ToJavaScript(javascript)) return false; } javascript << L"}\n"; - return true; + return !CXFA_IsTooBig(javascript); } bool CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"{\n"; @@ -276,11 +278,12 @@ bool CXFA_FMBlockExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { ret = expr->ToImpliedReturnJS(javascript); else ret = expr->ToJavaScript(javascript); - if (!ret || CXFA_IsTooBig(javascript)) + + if (!ret) return false; } javascript << L"}\n"; - return true; + return !CXFA_IsTooBig(javascript); } CXFA_FMDoExpression::CXFA_FMDoExpression( @@ -292,7 +295,7 @@ CXFA_FMDoExpression::~CXFA_FMDoExpression() {} bool CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; return m_pList->ToJavaScript(javascript); @@ -300,7 +303,7 @@ bool CXFA_FMDoExpression::ToJavaScript(CFX_WideTextBuf& javascript) { bool CXFA_FMDoExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; return m_pList->ToImpliedReturnJS(javascript); @@ -320,7 +323,7 @@ CXFA_FMIfExpression::~CXFA_FMIfExpression() {} bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"if ("; @@ -360,7 +363,7 @@ bool CXFA_FMIfExpression::ToJavaScript(CFX_WideTextBuf& javascript) { bool CXFA_FMIfExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; @@ -403,12 +406,12 @@ CXFA_FMLoopExpression::~CXFA_FMLoopExpression() {} bool CXFA_FMLoopExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - return depthManager.IsWithinMaxDepth(); + return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth(); } -bool CXFA_FMLoopExpression::ToImpliedReturnJS(CFX_WideTextBuf&) { +bool CXFA_FMLoopExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - return depthManager.IsWithinMaxDepth(); + return !CXFA_IsTooBig(javascript) && depthManager.IsWithinMaxDepth(); } CXFA_FMWhileExpression::CXFA_FMWhileExpression( @@ -423,7 +426,7 @@ CXFA_FMWhileExpression::~CXFA_FMWhileExpression() {} bool CXFA_FMWhileExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"while ("; @@ -440,7 +443,7 @@ bool CXFA_FMWhileExpression::ToJavaScript(CFX_WideTextBuf& javascript) { bool CXFA_FMWhileExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; @@ -464,24 +467,24 @@ CXFA_FMBreakExpression::~CXFA_FMBreakExpression() {} bool CXFA_FMBreakExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"break;\n"; - return true; + return !CXFA_IsTooBig(javascript); } bool CXFA_FMBreakExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"break;\n"; - return true; + return !CXFA_IsTooBig(javascript); } CXFA_FMContinueExpression::CXFA_FMContinueExpression(uint32_t line) @@ -491,24 +494,24 @@ CXFA_FMContinueExpression::~CXFA_FMContinueExpression() {} bool CXFA_FMContinueExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"continue;\n"; - return true; + return !CXFA_IsTooBig(javascript); } bool CXFA_FMContinueExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; javascript << L" = 0;\n"; javascript << L"continue;\n"; - return true; + return !CXFA_IsTooBig(javascript); } CXFA_FMForExpression::CXFA_FMForExpression( @@ -531,7 +534,7 @@ CXFA_FMForExpression::~CXFA_FMForExpression() {} bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"{\nvar "; @@ -554,8 +557,6 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { return false; javascript << L"); "; javascript << tempVariant; - if (CXFA_IsTooBig(javascript)) - return false; javascript << (m_bDirection ? kLessEqual : kGreaterEqual); javascript << XFA_FM_EXPTypeToString(GETFMVALUE); @@ -574,8 +575,6 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { if (!m_pStep->ToJavaScript(javascript)) return false; javascript << L")"; - if (CXFA_IsTooBig(javascript)) - return false; } else { javascript << L"1"; } @@ -588,7 +587,7 @@ bool CXFA_FMForExpression::ToJavaScript(CFX_WideTextBuf& javascript) { bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; @@ -613,8 +612,6 @@ bool CXFA_FMForExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { return false; javascript << L"); "; javascript << tempVariant; - if (CXFA_IsTooBig(javascript)) - return false; javascript << (m_bDirection ? kLessEqual : kGreaterEqual); javascript << XFA_FM_EXPTypeToString(GETFMVALUE); @@ -660,7 +657,7 @@ CXFA_FMForeachExpression::~CXFA_FMForeachExpression() {} bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << L"{\n"; @@ -685,8 +682,6 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { return false; if (expr != m_pAccessors.back()) javascript << L", "; - if (CXFA_IsTooBig(javascript)) - return false; } javascript << L");\n"; javascript << L"var "; @@ -719,7 +714,7 @@ bool CXFA_FMForeachExpression::ToJavaScript(CFX_WideTextBuf& javascript) { bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { CXFA_FMToJavaScriptDepth depthManager; - if (!depthManager.IsWithinMaxDepth()) + if (CXFA_IsTooBig(javascript) || !depthManager.IsWithinMaxDepth()) return false; javascript << RUNTIMEFUNCTIONRETURNVALUE; @@ -745,8 +740,6 @@ bool CXFA_FMForeachExpression::ToImpliedReturnJS(CFX_WideTextBuf& javascript) { return false; if (expr != m_pAccessors.back()) javascript << L", "; - if (CXFA_IsTooBig(javascript)) - return false; } javascript << L");\n"; javascript << L"var "; |