github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/internal/yaml/yaml_test.go (about) 1 package yaml 2 3 import ( 4 "bytes" 5 "testing" 6 7 "gotest.tools/assert" 8 ) 9 10 func TestDecoderYamlBomb(t *testing.T) { 11 var v map[interface{}]interface{} 12 data := []byte(`version: "3" 13 services: &services ["lol","lol","lol","lol","lol","lol","lol","lol","lol"] 14 b: &b [*services,*services,*services,*services,*services,*services,*services,*services,*services] 15 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b] 16 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c] 17 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d] 18 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e] 19 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f] 20 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g] 21 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]`) 22 d := NewDecoder(bytes.NewBuffer(data)) 23 err := d.Decode(&v) 24 assert.ErrorContains(t, err, "yaml: document contains excessive aliasing") 25 } 26 27 func TestUnmarshalYamlBomb(t *testing.T) { 28 var v map[interface{}]interface{} 29 data := []byte(`version: "3" 30 services: &services ["lol","lol","lol","lol","lol","lol","lol","lol","lol"] 31 b: &b [*services,*services,*services,*services,*services,*services,*services,*services,*services] 32 c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b] 33 d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c] 34 e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d] 35 f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e] 36 g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f] 37 h: &h [*g,*g,*g,*g,*g,*g,*g,*g,*g] 38 i: &i [*h,*h,*h,*h,*h,*h,*h,*h,*h]`) 39 err := Unmarshal(data, &v) 40 assert.ErrorContains(t, err, "yaml: document contains excessive aliasing") 41 }