-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
text/template: stack overflow #15618
Comments
go 1.6.2 package main
import (
"text/template"
"io/ioutil"
)
func main() {
template.Must(template.New("a").Parse(`{{template "a"}}`)).Execute(ioutil.Discard, nil)
} package main
import (
"text/template"
"io/ioutil"
)
func main() {
t := template.New("")
template.Must(t.New("a").Parse(`{{template "b"}}`))
template.Must(t.New("b").Parse(`{{template "a"}}`))
t.ExecuteTemplate(ioutil.Discard, "a", nil)
}
|
These both look like legitimate recursions to me. The true question is whether the recursion should be detected and I'm undecided about that. |
@robpike Why does |
A block defines a template, so we could make it so that it is not possible for a block to re-define the template in which the block appears. But even if that were done, it would still be possible to construct a cycle of nested templates if you try hard enough. |
For context, go-fuzz constantly hits recursive template invocations. The simplest case is when template "foo" contains {{template "foo"}}. I had to filter out all inputs that contain string "template". It's a user input error, but it manifests as hard program crash. I hoped that I will be at least tests blocks. But now go-fuzz discovered a way to cause recursion using blocks as well. Overriding an existing template with block sounds good. It is possible to trigger recursion using blocks? E.g. if block "foo" calls block "bar" and vise versa. Or it will fail because bar is not refined yet? If it is not possible to trigger recursion this way then I will be able to test at least blocks. |
You can create recursion with blocks:
But you can also trigger recursion with functions:
What does go-fuzz do to avoid that? Or has it just not run into it yet? |
I don't know. Maybe it run into it. I looked at some reports, but I also instantly deleted lots of them. |
I'm going to close this because I don't think there's anything practical we should do about it. Thanks for the report. |
Well, the evaluator could barf if the stack depth is unreasonably large. Maybe that's better than running the machine out of memory. |
Sent a CL |
CL https://golang.org/cl/23091 mentions this issue. |
go version devel +149ac34 Mon May 9 17:50:29 2016 +0000 linux/amd64
The following program causes stack overflow. Documentation suggests that block calls itself rather than the top-level "" template, so there should be no recursion.
Found with go-fuzz.
The text was updated successfully, but these errors were encountered: