mirror of
https://github.com/kubernetes/sample-controller.git
synced 2025-03-26 00:31:15 +08:00
Merge pull request #83436 from liggitt/automated-cherry-pick-of-#83261-upstream-release-1.13-1570075716
[1.13] Automated cherry pick of #83261: bump gopkg.in/yaml.v2 v2.2.4 Kubernetes-commit: 17c28f0e1c6733b02a62471c813b262df7681789
This commit is contained in:
parent
1fbb8791a9
commit
e3c0944ed2
488
Godeps/Godeps.json
generated
488
Godeps/Godeps.json
generated
File diff suppressed because it is too large
Load Diff
38
vendor/gopkg.in/yaml.v2/decode.go
generated
vendored
38
vendor/gopkg.in/yaml.v2/decode.go
generated
vendored
@ -229,6 +229,10 @@ type decoder struct {
|
|||||||
mapType reflect.Type
|
mapType reflect.Type
|
||||||
terrors []string
|
terrors []string
|
||||||
strict bool
|
strict bool
|
||||||
|
|
||||||
|
decodeCount int
|
||||||
|
aliasCount int
|
||||||
|
aliasDepth int
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -314,7 +318,39 @@ func (d *decoder) prepare(n *node, out reflect.Value) (newout reflect.Value, unm
|
|||||||
return out, false, false
|
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) {
|
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) > allowedAliasRatio(d.decodeCount) {
|
||||||
|
failf("document contains excessive aliasing")
|
||||||
|
}
|
||||||
switch n.kind {
|
switch n.kind {
|
||||||
case documentNode:
|
case documentNode:
|
||||||
return d.document(n, out)
|
return d.document(n, out)
|
||||||
@ -353,7 +389,9 @@ func (d *decoder) alias(n *node, out reflect.Value) (good bool) {
|
|||||||
failf("anchor '%s' value contains itself", n.value)
|
failf("anchor '%s' value contains itself", n.value)
|
||||||
}
|
}
|
||||||
d.aliases[n] = true
|
d.aliases[n] = true
|
||||||
|
d.aliasDepth++
|
||||||
good = d.unmarshal(n.alias, out)
|
good = d.unmarshal(n.alias, out)
|
||||||
|
d.aliasDepth--
|
||||||
delete(d.aliases, n)
|
delete(d.aliases, n)
|
||||||
return good
|
return good
|
||||||
}
|
}
|
||||||
|
28
vendor/gopkg.in/yaml.v2/encode.go
generated
vendored
28
vendor/gopkg.in/yaml.v2/encode.go
generated
vendored
@ -13,6 +13,19 @@ import (
|
|||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// jsonNumber is the interface of the encoding/json.Number datatype.
|
||||||
|
// Repeating the interface here avoids a dependency on encoding/json, and also
|
||||||
|
// supports other libraries like jsoniter, which use a similar datatype with
|
||||||
|
// the same interface. Detecting this interface is useful when dealing with
|
||||||
|
// structures containing json.Number, which is a string under the hood. The
|
||||||
|
// encoder should prefer the use of Int64(), Float64() and string(), in that
|
||||||
|
// order, when encoding this type.
|
||||||
|
type jsonNumber interface {
|
||||||
|
Float64() (float64, error)
|
||||||
|
Int64() (int64, error)
|
||||||
|
String() string
|
||||||
|
}
|
||||||
|
|
||||||
type encoder struct {
|
type encoder struct {
|
||||||
emitter yaml_emitter_t
|
emitter yaml_emitter_t
|
||||||
event yaml_event_t
|
event yaml_event_t
|
||||||
@ -89,6 +102,21 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
|
|||||||
}
|
}
|
||||||
iface := in.Interface()
|
iface := in.Interface()
|
||||||
switch m := iface.(type) {
|
switch m := iface.(type) {
|
||||||
|
case jsonNumber:
|
||||||
|
integer, err := m.Int64()
|
||||||
|
if err == nil {
|
||||||
|
// In this case the json.Number is a valid int64
|
||||||
|
in = reflect.ValueOf(integer)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
float, err := m.Float64()
|
||||||
|
if err == nil {
|
||||||
|
// In this case the json.Number is a valid float64
|
||||||
|
in = reflect.ValueOf(float)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// fallback case - no number could be obtained
|
||||||
|
in = reflect.ValueOf(m.String())
|
||||||
case time.Time, *time.Time:
|
case time.Time, *time.Time:
|
||||||
// Although time.Time implements TextMarshaler,
|
// Although time.Time implements TextMarshaler,
|
||||||
// we don't want to treat it as a string for YAML
|
// we don't want to treat it as a string for YAML
|
||||||
|
2
vendor/gopkg.in/yaml.v2/resolve.go
generated
vendored
2
vendor/gopkg.in/yaml.v2/resolve.go
generated
vendored
@ -81,7 +81,7 @@ func resolvableTag(tag string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`)
|
var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`)
|
||||||
|
|
||||||
func resolve(tag string, in string) (rtag string, out interface{}) {
|
func resolve(tag string, in string) (rtag string, out interface{}) {
|
||||||
if !resolvableTag(tag) {
|
if !resolvableTag(tag) {
|
||||||
|
16
vendor/gopkg.in/yaml.v2/scannerc.go
generated
vendored
16
vendor/gopkg.in/yaml.v2/scannerc.go
generated
vendored
@ -906,6 +906,9 @@ func yaml_parser_remove_simple_key(parser *yaml_parser_t) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// max_flow_level limits the flow_level
|
||||||
|
const max_flow_level = 10000
|
||||||
|
|
||||||
// Increase the flow level and resize the simple key list if needed.
|
// Increase the flow level and resize the simple key list if needed.
|
||||||
func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool {
|
func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool {
|
||||||
// Reset the simple key on the next level.
|
// Reset the simple key on the next level.
|
||||||
@ -913,6 +916,11 @@ func yaml_parser_increase_flow_level(parser *yaml_parser_t) bool {
|
|||||||
|
|
||||||
// Increase the flow level.
|
// Increase the flow level.
|
||||||
parser.flow_level++
|
parser.flow_level++
|
||||||
|
if parser.flow_level > max_flow_level {
|
||||||
|
return yaml_parser_set_scanner_error(parser,
|
||||||
|
"while increasing flow level", parser.simple_keys[len(parser.simple_keys)-1].mark,
|
||||||
|
fmt.Sprintf("exceeded max depth of %d", max_flow_level))
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -925,6 +933,9 @@ func yaml_parser_decrease_flow_level(parser *yaml_parser_t) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// max_indents limits the indents stack size
|
||||||
|
const max_indents = 10000
|
||||||
|
|
||||||
// Push the current indentation level to the stack and set the new level
|
// Push the current indentation level to the stack and set the new level
|
||||||
// the current column is greater than the indentation level. In this case,
|
// the current column is greater than the indentation level. In this case,
|
||||||
// append or insert the specified token into the token queue.
|
// append or insert the specified token into the token queue.
|
||||||
@ -939,6 +950,11 @@ func yaml_parser_roll_indent(parser *yaml_parser_t, column, number int, typ yaml
|
|||||||
// indentation level.
|
// indentation level.
|
||||||
parser.indents = append(parser.indents, parser.indent)
|
parser.indents = append(parser.indents, parser.indent)
|
||||||
parser.indent = column
|
parser.indent = column
|
||||||
|
if len(parser.indents) > max_indents {
|
||||||
|
return yaml_parser_set_scanner_error(parser,
|
||||||
|
"while increasing indent level", parser.simple_keys[len(parser.simple_keys)-1].mark,
|
||||||
|
fmt.Sprintf("exceeded max depth of %d", max_indents))
|
||||||
|
}
|
||||||
|
|
||||||
// Create a token and insert it into the queue.
|
// Create a token and insert it into the queue.
|
||||||
token := yaml_token_t{
|
token := yaml_token_t{
|
||||||
|
20
vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
generated
vendored
20
vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go
generated
vendored
@ -100,7 +100,27 @@ func (customNumberDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
|
|||||||
}
|
}
|
||||||
iter.ReportError("DecodeNumber", err.Error())
|
iter.ReportError("DecodeNumber", err.Error())
|
||||||
default:
|
default:
|
||||||
|
// init depth, if needed
|
||||||
|
if iter.Attachment == nil {
|
||||||
|
iter.Attachment = int(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// remember current depth
|
||||||
|
originalAttachment := iter.Attachment
|
||||||
|
|
||||||
|
// increment depth before descending
|
||||||
|
if i, ok := iter.Attachment.(int); ok {
|
||||||
|
iter.Attachment = i + 1
|
||||||
|
if i > 10000 {
|
||||||
|
iter.ReportError("parse", "exceeded max depth")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
*(*interface{})(ptr) = iter.Read()
|
*(*interface{})(ptr) = iter.Read()
|
||||||
|
|
||||||
|
// restore current depth
|
||||||
|
iter.Attachment = originalAttachment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
vendor/k8s.io/apimachinery/pkg/util/json/json.go
generated
vendored
28
vendor/k8s.io/apimachinery/pkg/util/json/json.go
generated
vendored
@ -19,6 +19,7 @@ package json
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,6 +35,9 @@ func Marshal(v interface{}) ([]byte, error) {
|
|||||||
return json.Marshal(v)
|
return json.Marshal(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// limit recursive depth to prevent stack overflow errors
|
||||||
|
const maxDepth = 10000
|
||||||
|
|
||||||
// Unmarshal unmarshals the given data
|
// Unmarshal unmarshals the given data
|
||||||
// If v is a *map[string]interface{}, numbers are converted to int64 or float64
|
// If v is a *map[string]interface{}, numbers are converted to int64 or float64
|
||||||
func Unmarshal(data []byte, v interface{}) error {
|
func Unmarshal(data []byte, v interface{}) error {
|
||||||
@ -48,7 +52,7 @@ func Unmarshal(data []byte, v interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
|
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
|
||||||
return convertMapNumbers(*v)
|
return convertMapNumbers(*v, 0)
|
||||||
|
|
||||||
case *[]interface{}:
|
case *[]interface{}:
|
||||||
// Build a decoder from the given data
|
// Build a decoder from the given data
|
||||||
@ -60,7 +64,7 @@ func Unmarshal(data []byte, v interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
|
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
|
||||||
return convertSliceNumbers(*v)
|
return convertSliceNumbers(*v, 0)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return json.Unmarshal(data, v)
|
return json.Unmarshal(data, v)
|
||||||
@ -69,16 +73,20 @@ func Unmarshal(data []byte, v interface{}) error {
|
|||||||
|
|
||||||
// convertMapNumbers traverses the map, converting any json.Number values to int64 or float64.
|
// convertMapNumbers traverses the map, converting any json.Number values to int64 or float64.
|
||||||
// values which are map[string]interface{} or []interface{} are recursively visited
|
// values which are map[string]interface{} or []interface{} are recursively visited
|
||||||
func convertMapNumbers(m map[string]interface{}) error {
|
func convertMapNumbers(m map[string]interface{}, depth int) error {
|
||||||
|
if depth > maxDepth {
|
||||||
|
return fmt.Errorf("exceeded max depth of %d", maxDepth)
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case json.Number:
|
case json.Number:
|
||||||
m[k], err = convertNumber(v)
|
m[k], err = convertNumber(v)
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
err = convertMapNumbers(v)
|
err = convertMapNumbers(v, depth+1)
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
err = convertSliceNumbers(v)
|
err = convertSliceNumbers(v, depth+1)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -89,16 +97,20 @@ func convertMapNumbers(m map[string]interface{}) error {
|
|||||||
|
|
||||||
// convertSliceNumbers traverses the slice, converting any json.Number values to int64 or float64.
|
// convertSliceNumbers traverses the slice, converting any json.Number values to int64 or float64.
|
||||||
// values which are map[string]interface{} or []interface{} are recursively visited
|
// values which are map[string]interface{} or []interface{} are recursively visited
|
||||||
func convertSliceNumbers(s []interface{}) error {
|
func convertSliceNumbers(s []interface{}, depth int) error {
|
||||||
|
if depth > maxDepth {
|
||||||
|
return fmt.Errorf("exceeded max depth of %d", maxDepth)
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
for i, v := range s {
|
for i, v := range s {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
case json.Number:
|
case json.Number:
|
||||||
s[i], err = convertNumber(v)
|
s[i], err = convertNumber(v)
|
||||||
case map[string]interface{}:
|
case map[string]interface{}:
|
||||||
err = convertMapNumbers(v)
|
err = convertMapNumbers(v, depth+1)
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
err = convertSliceNumbers(v)
|
err = convertSliceNumbers(v, depth+1)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user