]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: increase nesting depth limit for type descriptors
authorRobert Griesemer <gri@golang.org>
Mon, 17 Dec 2018 22:42:29 +0000 (14:42 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 18 Dec 2018 00:13:58 +0000 (00:13 +0000)
The formatting routines for types use a depth limit as primitive
mechanism to detect cycles. For now, increase the limit from 100
to 250 and file #29312 so we don't drop this on the floor.

Also, adjust some fatal error messages elsewhere to use
better formatting.

Fixes #29264.
Updates #29312.

Change-Id: Idd529f6682d478e0dcd2d469cb802192190602f6
Reviewed-on: https://go-review.googlesource.com/c/154583
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/gc/iimport.go
test/fixedbugs/issue29264.go [new file with mode: 0644]

index f128872dbba3b25edf848e987d54a7d08c998cd3..baea4cc7161c45a1f3b7a5a3ff0bbd50138e2f37 100644 (file)
@@ -1749,7 +1749,11 @@ func tconv(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string {
                return t.FieldType(0).String() + "," + t.FieldType(1).String()
        }
 
-       if depth > 100 {
+       // Avoid endless recursion by setting an upper limit. This also
+       // limits the depths of valid composite types, but they are likely
+       // artificially created.
+       // TODO(gri) should have proper cycle detection here, eventually (issue #29312)
+       if depth > 250 {
                return "<...>"
        }
 
index cc43c2e2876d26a33f19d8450b2f30870ceb2fbd..2a34e2ea778f735ed307557ab9a56d4196c93b7d 100644 (file)
@@ -1325,7 +1325,7 @@ func (w *exportWriter) expr(n *Node) {
 
        default:
                Fatalf("cannot export %v (%d) node\n"+
-                       "==> please file an issue and assign to gri@\n", n.Op, int(n.Op))
+                       "\t==> please file an issue and assign to gri@", n.Op, int(n.Op))
        }
 }
 
index ff98b79835f27de45f7c1439b927d7bf087f75b7..addf829b04a969bb466579fd904d606af11180c1 100644 (file)
@@ -1053,7 +1053,7 @@ func (r *importReader) node() *Node {
 
        default:
                Fatalf("cannot import %v (%d) node\n"+
-                       "==> please file an issue and assign to gri@\n", op, int(op))
+                       "\t==> please file an issue and assign to gri@", op, int(op))
                panic("unreachable") // satisfy compiler
        }
 }
diff --git a/test/fixedbugs/issue29264.go b/test/fixedbugs/issue29264.go
new file mode 100644 (file)
index 0000000..3781559
--- /dev/null
@@ -0,0 +1,22 @@
+// run
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Verify that we emit a valid type descriptor for
+// a fairly deeply nested type.
+
+package main
+
+import "fmt"
+import "strings"
+
+func main() {
+       a := [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]int{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{42}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
+       got := fmt.Sprint(a)
+       want := strings.Repeat("[", 100) + "42" + strings.Repeat("]", 100)
+       if got != want {
+               fmt.Printf("got  %q\nwant %q\n", got, want)
+       }
+}