1 // Copyright 2017 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef XFA_FXFA_FM2JS_CXFA_FMTOJAVASCRIPTDEPTH_H_ 6 #define XFA_FXFA_FM2JS_CXFA_FMTOJAVASCRIPTDEPTH_H_ 7 8 class CXFA_FMToJavaScriptDepth { 9 public: CXFA_FMToJavaScriptDepth()10 CXFA_FMToJavaScriptDepth() { depth_++; } ~CXFA_FMToJavaScriptDepth()11 ~CXFA_FMToJavaScriptDepth() { depth_--; } 12 IsWithinMaxDepth()13 bool IsWithinMaxDepth() const { return depth_ <= kMaxDepth; } 14 15 static void Reset(); 16 17 private: 18 // Arbitarily picked by looking at how deep a translation got before hitting 19 // the getting fuzzer memory limits. Should be larger then |kMaxParseDepth| in 20 // cxfa_fmparser.cpp. 21 const unsigned long kMaxDepth = 5000; 22 23 static unsigned long depth_; 24 }; 25 26 #endif // XFA_FXFA_FM2JS_CXFA_FMTOJAVASCRIPTDEPTH_H_ 27