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

c.ShouldBind() maybe will stack overflow #2203

Open
vvlgo opened this issue Jan 9, 2020 · 1 comment
Open

c.ShouldBind() maybe will stack overflow #2203

vvlgo opened this issue Jan 9, 2020 · 1 comment

Comments

@vvlgo
Copy link

vvlgo commented Jan 9, 2020

  • With issues:
    • Use the search tool before opening a new issue.
    • Please provide source code and commit sha if you found a bug.
    • Review existing issues and provide feedback or react to them.

Description

I used a structure, and the type of a field is itself. When I upload form data and receive it with shoudbind, the stack overflows. Please use the following code to reproduce. I hope to solve this problem. Thank you

How to reproduce

package main

import (
	"github.com/gin-gonic/gin"
)
//post form-data a
func main() {
	r := gin.Default()
	r.POST("/test", TestShoudbind)
	r.Run(":8080")
}

func TestShoudbind(c *gin.Context){
	a := A{}
	c.ShouldBind(&a)
	c.JSON(200,a)
}

type A struct {
	B string `form:"b" json:"b"`
	L *A     `json:"l"`
}

Expectations

postman 
post http://localhost:8080/test
form-data
b test111

json:{"b":"test111","l":nil}

Actual result

postman 
post http://localhost:8080/test
form-data
b test111

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

Environment

  • go version:1.3.5
  • gin version (or commit ref):1.4.0
  • operating system:macos10.15.2
@JellyZhang
Copy link

Duplicate of #1978
This problem is caused by circular reference.
You can ignore this field with tag form:"-" like this:

type A struct {
	B string `form:"b" json:"b"`
	L *A     `form:"-" json:"l"`
}

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