summaryrefslogtreecommitdiff
path: root/vendor/gopkg.in/yaml.v2/decode.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-10-04 08:45:34 -0700
committerGitHub <noreply@github.com>2019-10-04 08:45:34 -0700
commitc03b1b95a3e1333696053fbd8701721d6b206f56 (patch)
tree6f3a37c57c5c6dc98755832ffa0f8dd4b9020d0d /vendor/gopkg.in/yaml.v2/decode.go
parent70d5b0a6fbb86174e113d8a8a3b4b40eb7b7a297 (diff)
parentf418fc70e7fe6e55c95d2130e52dee7f360eeff4 (diff)
downloadpodman-c03b1b95a3e1333696053fbd8701721d6b206f56.tar.gz
podman-c03b1b95a3e1333696053fbd8701721d6b206f56.tar.bz2
podman-c03b1b95a3e1333696053fbd8701721d6b206f56.zip
Merge pull request #4194 from containers/dependabot/go_modules/gopkg.in/yaml.v2-2.2.4
Bump gopkg.in/yaml.v2 from 2.2.3 to 2.2.4
Diffstat (limited to 'vendor/gopkg.in/yaml.v2/decode.go')
-rw-r--r--vendor/gopkg.in/yaml.v2/decode.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/vendor/gopkg.in/yaml.v2/decode.go b/vendor/gopkg.in/yaml.v2/decode.go
index 91679b5b4..531087655 100644
--- a/vendor/gopkg.in/yaml.v2/decode.go
+++ b/vendor/gopkg.in/yaml.v2/decode.go
@@ -318,12 +318,37 @@ func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unm
return out, false, false
}
+const (
+ // 400,000 decode operations is ~500kb of dense object declarations, or ~5kb of dense object declarations with 10000% alias expansion
+ alias_ratio_range_low = 400000
+ // 4,000,000 decode operations is ~5MB of dense object declarations, or ~4.5MB of dense object declarations with 10% alias expansion
+ alias_ratio_range_high = 4000000
+ // alias_ratio_range is the range over which we scale allowed alias ratios
+ alias_ratio_range = float64(alias_ratio_range_high - alias_ratio_range_low)
+)
+
+func allowedAliasRatio(decodeCount int) float64 {
+ switch {
+ case decodeCount <= alias_ratio_range_low:
+ // allow 99% to come from alias expansion for small-to-medium documents
+ return 0.99
+ case decodeCount >= alias_ratio_range_high:
+ // allow 10% to come from alias expansion for very large documents
+ return 0.10
+ default:
+ // scale smoothly from 99% down to 10% over the range.
+ // this maps to 396,000 - 400,000 allowed alias-driven decodes over the range.
+ // 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps).
+ return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range)
+ }
+}
+
func (d *decoder) unmarshal(n *node, out reflect.Value) (good bool) {
d.decodeCount++
if d.aliasDepth > 0 {
d.aliasCount++
}
- if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > 0.99 {
+ if d.aliasCount > 100 && d.decodeCount > 1000 && float64(d.aliasCount)/float64(d.decodeCount) > allowedAliasRatio(d.decodeCount) {
failf("document contains excessive aliasing")
}
switch n.kind {