global_private.hh
2.72 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef GLOBAL_PRIVATE_HH
#define GLOBAL_PRIVATE_HH
#include <qpdf/global.hh>
#include <limits>
namespace qpdf::global
{
class Limits
{
public:
Limits(Limits const&) = delete;
Limits(Limits&&) = delete;
Limits& operator=(Limits const&) = delete;
Limits& operator=(Limits&&) = delete;
static uint32_t const&
parser_max_nesting()
{
return l.parser_max_nesting_;
}
static void
parser_max_nesting(uint32_t value)
{
l.parser_max_nesting_ = value;
}
static uint32_t const&
parser_max_errors()
{
return l.parser_max_errors_;
}
static void
parser_max_errors(uint32_t value)
{
l.parser_max_errors_set_ = true;
l.parser_max_errors_ = value;
}
static uint32_t const&
parser_max_container_size(bool damaged)
{
return damaged ? l.parser_max_container_size_damaged_ : l.parser_max_container_size_;
}
static void parser_max_container_size(bool damaged, uint32_t value);
/// Record a limit error.
static void
error()
{
if (l.errors_ < std::numeric_limits<uint32_t>::max()) {
++l.errors_;
}
}
static uint32_t const&
errors()
{
return l.errors_;
}
static void disable_defaults();
private:
Limits() = default;
~Limits() = default;
static Limits l;
uint32_t errors_{0};
uint32_t parser_max_nesting_{499};
uint32_t parser_max_errors_{15};
bool parser_max_errors_set_{false};
uint32_t parser_max_container_size_{std::numeric_limits<uint32_t>::max()};
uint32_t parser_max_container_size_damaged_{5'000};
bool parser_max_container_size_damaged_set_{false};
};
class Options
{
public:
static bool
inspection_mode()
{
return static_cast<bool>(o.inspection_mode_);
}
static void
inspection_mode(bool value)
{
if (value) {
o.inspection_mode_ = true;
}
}
static bool
default_limits()
{
return static_cast<bool>(o.default_limits_);
}
static void
default_limits(bool value)
{
if (!value) {
o.default_limits_ = false;
Limits::disable_defaults();
}
}
private:
static Options o;
bool inspection_mode_{false};
bool default_limits_{true};
};
} // namespace qpdf::global
#endif // GLOBAL_PRIVATE_HH