Skip to content
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

Massive file generated do to recursion with no errors #70

Open
charlesritchea opened this issue Jul 1, 2019 · 2 comments
Open

Massive file generated do to recursion with no errors #70

charlesritchea opened this issue Jul 1, 2019 · 2 comments

Comments

@charlesritchea
Copy link

This bug is kind of hilarious, so we have an html file template that we include in our bin with vfsgen in a package called assets, but because go generate puts the assets_vfsdata.go in the root directory, we move it into assets folder after it's generated. After repeating this process with the assets_vfsdata.go in there, the generated assets_vfsdata.go was ~1.8GB!! with no errors of any kind reported. Of course I changed the directory structure to prevent this, but I found it very interesting that this is possible without a stack overflow of some kind.

File system:
./assets/report-template.html
./assets/assets_vfsdata.go // after initial generation and copying from ./assets_vfsdata.go

`// +build ignore

package main

import (
"log"
"net/http"

"github.com/shurcooL/vfsgen"

)

func main() {
var fs http.FileSystem = http.Dir("./assets")

err := vfsgen.Generate(fs, vfsgen.Options{
	PackageName:  "assets",
	BuildTags:    "!dev",
	VariableName: "Assets",
})
if err != nil {
	log.Fatalln(err)
}

}
`

I switched to http.Dir("./assets/src")
and moved report-template.html into ./assets/src to fix this, but I was pretty surprised that it was even possible

@charlesritchea
Copy link
Author

I'm not sure if the file is huge the second iteration, or if it doubles in size each iteration until reaching some limit

@dmitshur
Copy link
Member

dmitshur commented Aug 12, 2019

Thanks for sharing this scenario that you've encountered.

vfsgen is a simple tool that operates on whatever arbitrary input you provide it. I'm not sure if it's viable to detect that its own output is a part of the input, at least not in the general case.

Right now, I can't think of anything that can be done to improve the situation here. Let me know if you have suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants