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

fix(form):add max iteration to avoid stack overflow #3701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

and1gaoc
Copy link

example code:

type People struct {
	Name    string  `form:"name"`
	Teacher Teacher `form:"teacher"`
}

type Teacher struct {
	Owner *People `form:"owner"`
}

router := gin.Default()
router.GET("/search", func(c *gin.Context) {
	var req People
	if err := c.ShouldBindQuery(&req); err != nil {
		c.String(http.StatusBadRequest, "bad request")
		return
	}
	c.String(http.StatusOK, "Welcome Gin Server")
})

if param to be parsed contains nested field ,goroutine will crash

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020460418 stack=[0xc020460000, 0xc040460000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x13bad15?, 0x16315c0?})
/usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x700007c93da0 sp=0x700007c93d70 pc=0x10345bd
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1104 +0x5cc fp=0x700007c93f58 sp=0x700007c93da0 pc=0x104dcec
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:570 +0x8b fp=0x700007c93f60 sp=0x700007c93f58 pc=0x10636cb

goroutine 7 [running]:
runtime.heapBitsSetType(0xc001c7f350?, 0x18?, 0x18?, 0x1377180?)
/usr/local/go/src/runtime/mbitmap.go:844 +0xbac fp=0xc020460428 sp=0xc020460420 pc=0x101556c
runtime.mallocgc(0x18, 0x1377180, 0x1)
/usr/local/go/src/runtime/malloc.go:1050 +0x64d fp=0xc0204604a0 sp=0xc020460428 pc=0x100cb6d
reflect.unsafe_New(0x7?)
/usr/local/go/src/runtime/malloc.go:1197 +0x27 fp=0xc0204604c8 sp=0xc0204604a0 pc=0x105eba7
reflect.New({0x1465920?, 0x1377180})
/usr/local/go/src/reflect/value.go:3139 +0x5d fp=0xc0204604f8 sp=0xc0204604c8 pc=0x10aaffd
github.com/gin-gonic/gin/binding.mapping({0x1341520?, 0xc001c7f348?, 0xc001c80a20?}, {{0x133308c, 0x5}, {0x0, 0x0}, {0x1465920, 0x1341520}, {0x1333092, ...}, ...}, ...)
/Users/gaochong/GoProjects/gin/binding/form_mapping.go:81 +0x27d fp=0xc0204606e0 sp=0xc0204604f8 pc=0x131429d
github.com/gin-gonic/gin/binding.mapping({0x136d4c0?, 0xc001c7f348?, 0x0?}, {{0x13362f0, 0x7}, {0x0, 0x0}, {0x1465920, 0x136d4c0}, {0x13362f8, ...}, ...}, ...)
/Users/gaochong/GoProjects/gin/binding/form_mapping.go:112 +0x550 fp=0xc0204608c8 sp=0xc0204606e0 pc=0x1314570
github.com/gin-gonic/gin/binding.mapping({0x1377180?, 0xc001c7f338?, 0xc001c80a00?}, {{0x133308c, 0x5}, {0x0, 0x0}, {0x1465920, 0x1341520}, {0x1333092, ...}, ...}, ...)
/Users/gaochong/GoProjects/gin/binding/form_mapping.go:112 +0x550 fp=0xc020460ab0 sp=0xc0204608c8 pc=0x1314570
github.com/gin-gonic/gin/binding.mapping({0x1341520?, 0xc001c7f330?, 0xc001c809f0?}, {{0x133308c, 0x5}, {0x0, 0x0}, {0x1465920, 0x1341520}, {0x1333092, ...}, ...}, ...)
/Users/gaochong/GoProjects/gin/binding/form_mapping.go:83 +0x318 fp=0xc020460c98 sp=0xc020460ab0 pc=0x1314338
github.com/gin-gonic/gin/binding.mapping({0x136d4c0?, 0xc001c7f330?, 0x0?}, {{0x13362f0, 0x7}, {0x0, 0x0}, {0x1465920, 0x136d4c0}, {0x13362f8, ...}, ...}, ...)
/Users/gaochong/GoProjects/gin/binding/form_mapping.go:112 +0x550 fp=0xc020460e80 sp=0xc020460c98 pc=0x1314570
github.com/gin-gonic/gin/binding.mapping({0x1377180?, 0xc001c7f320?, 0xc001c809d0?}, {{0x133308c, 0x5}, {0x0, 0x0}, {0x1465920, 0x1341520}, {0x1333092, ...}, ...}, ...)

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

Successfully merging this pull request may close these issues.

None yet

1 participant