Repository navigation
Expand file tree
/
Copy pathlimits.go
More file actions
61 lines (55 loc) · 1.65 KB
/
Copy pathlimits.go
File metadata and controls
61 lines (55 loc) · 1.65 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
package appmeta
// Limits bound the work Parse does on one input. The defaults fit real-world
// apps with a wide margin; lower them for tighter memory or latency budgets.
type Limits struct {
// MaxEntries is the most zip entries the archive may declare. It is
// checked before the central directory is read.
MaxEntries int
// MaxEntrySize is the most uncompressed bytes read from one zip entry.
MaxEntrySize int64
// MaxTotalSize is the most uncompressed bytes read across all entries.
MaxTotalSize int64
// MaxDepth is the deepest element nesting accepted in binary XML and plists.
MaxDepth int
// MaxIconPixels is the largest width*height of a source icon that will
// be decoded.
MaxIconPixels int
}
// MaxIconSize is the largest width and height of an extracted icon; larger
// icons are scaled down.
const MaxIconSize = 512
// DefaultLimits returns the limits Parse uses unless WithLimits overrides them.
func DefaultLimits() Limits {
return Limits{
MaxEntries: 200_000,
MaxEntrySize: 64 << 20,
MaxTotalSize: 256 << 20,
MaxDepth: 64,
MaxIconPixels: 4096 * 4096,
}
}
// Option configures Parse.
type Option func(*config)
type config struct {
limits Limits
}
// WithLimits overrides the default limits. Zero fields keep their default.
func WithLimits(l Limits) Option {
return func(c *config) {
if l.MaxEntries > 0 {
c.limits.MaxEntries = l.MaxEntries
}
if l.MaxEntrySize > 0 {
c.limits.MaxEntrySize = l.MaxEntrySize
}
if l.MaxTotalSize > 0 {
c.limits.MaxTotalSize = l.MaxTotalSize
}
if l.MaxDepth > 0 {
c.limits.MaxDepth = l.MaxDepth
}
if l.MaxIconPixels > 0 {
c.limits.MaxIconPixels = l.MaxIconPixels
}
}
}