summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-10-25 14:32:14 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-10-25 18:50:23 +0000
commit1e19e25cd10c24f25beddff56b7c4b5fdc5adbcb (patch)
tree0dbc342a37e7d28dbf76a0dc9a10d77fabe5f289 /xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h
parent8f524d6ff9c5c5e07388438e58aca7dc39f43a1f (diff)
downloadpdfium-1e19e25cd10c24f25beddff56b7c4b5fdc5adbcb.tar.xz
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 <rharrison@chromium.org> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h b/xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h
new file mode 100644
index 0000000000..14f87a68f5
--- /dev/null
+++ b/xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h
@@ -0,0 +1,22 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef XFA_FXFA_FM2JS_CXFA_FMTOJAVASCRIPTDEPTH_H_
+#define XFA_FXFA_FM2JS_CXFA_FMTOJAVASCRIPTDEPTH_H_
+
+class CXFA_FMToJavaScriptDepth {
+ public:
+ CXFA_FMToJavaScriptDepth() { depth_++; }
+ ~CXFA_FMToJavaScriptDepth() { depth_--; }
+
+ bool IsWithinMaxDepth() const { return depth_ <= max_depth_; }
+
+ static void Reset();
+
+ private:
+ static unsigned long depth_;
+ static unsigned long max_depth_;
+};
+
+#endif // XFA_FXFA_FM2JS_CXFA_FMTOJAVASCRIPTDEPTH_H_