| 6 | #define BASE_JSON_JSON_COMMON_H_ |
| 7 |
| 8 | #include <stddef.h> |
| 9 |
| 10 | #include "base/logging.h" |
| 11 | #include "base/macros.h" |
| 12 |
| 13 | namespace base { |
| 14 | namespace internal { |
| 15 |
| 16 | // Chosen to support 99.9% of documents found in the wild late 2016. |
| 17 | // http://crbug.com/673263 |
| 18 | const size_t kAbsoluteMaxDepth = 200; |
| 19 |
| 20 | // Simple class that checks for maximum recursion/stack overflow. |
| 21 | class StackMarker { |
| 22 | public: |
| 23 | StackMarker(size_t max_depth, size_t* depth) |
| 24 | : max_depth_(max_depth), depth_(depth) { |
| 25 | ++(*depth_); |
| 26 | DCHECK_LE(*depth_, max_depth_); |
| 27 | } |
| 28 | ~StackMarker() { --(*depth_); } |
| 29 |
| 30 | bool IsTooDeep() const { return *depth_ >= max_depth_; } |
| 31 |
| 32 | private: |
| 33 | const size_t max_depth_; |
| 34 | size_t* const depth_; |
| 35 |
| 36 | DISALLOW_COPY_AND_ASSIGN(StackMarker); |
| 37 | }; |
| 38 |
| 39 | } // namespace internal |
| 40 | } // namespace base |
| 41 |
| 42 | #endif // BASE_JSON_JSON_COMMON_H_ |
| 43 |