summaryrefslogtreecommitdiff
path: root/xfa/fxfa/fm2js/cxfa_fmtojavascriptdepth.h
blob: f4cd1be472945b5691309806041d2de8231027b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 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_ <= kMaxDepth; }

  static void Reset();

 private:
  // Arbitarily picked by looking at how deep a translation got before hitting
  // the getting fuzzer memory limits. Should be larger then |kMaxParseDepth| in
  // cxfa_fmparser.cpp.
  const unsigned long kMaxDepth = 5000;

  static unsigned long depth_;
};

#endif  // XFA_FXFA_FM2JS_CXFA_FMTOJAVASCRIPTDEPTH_H_