-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Wrong Content-Type leads to stack overflow #1978
Comments
What is the definition of the Organization structure? |
It's the FHIR resource "Organization", the definition is here and there are also some examples. I tested various JSON messages, even very simple ones, and the error was there. But I didn't checked, if the Go structure has a influence on the result, I will upload the structure on Monday and check if the behavior changes if I simplify it. |
I narrowed down the problem a little.
|
I reopened the issue, because it is a gin problem, I forgot, that the problem is only there when the Content-Type is wrong. |
Can you test this pr to fix the problem? |
Thank you very much for your work! The problem is still there, but the stack trace changed a little:
To give you some more information about whats happening I added some additional print statements to form_mapping.go. I added the statements after I captured the above stack trace, so the line numbers are correct:
In both cases I used an empty request body. |
Thank you, Can you give me the client test data, Server that can be run, and client code,this question looks very interesting. |
I created a repository with (hopefully) everything you need to reproduce the error. gin-stackoverflow-demo The tests commented with "Successful" do not end with a fatal error. |
In the go, the stack burst will occupy 1G memory, the error message is as follows ```runtime: goroutine stack exceeds 1000000000-byte limit``` If it is a user of gin, the structure of the circular reference is defined on the server side, and the server memory may be used up as long as 100 go processes, and even the server may be down. So I suggest that the mapping function should add a limit on the number of calls, and the number of times can be configured. Of course, I tried several other modifications when I solved the stackoverflow problem described in gin-gonic#1978, but it was not compatible with the existing API, so I did not adopt the solution I tried.
About the reasons of this problem: This problem happens only on "Form" binding, and does not depend on input data. When you select a Content-Type is <application/json>, the gin binding uses default golang "encoding/json" package for binding a structs, but by default gin uses the custom "Form" binding. Custom "Form" binding is walking by struct's fields, and if it sees the pointer to another struct then it go deeper (also if it is a nil pointer value). And for current implementation of "Form" binding there is no a detecting for a recurive struct definitions. In your case, type "Reference" and "Identifier" reference each to another, and "Form" binding is trying to create new empty struct, assign it and going deeper:
|
Thank you very much for the clarification. I leave it to the admins of this repo if they want to close this issue or not. Personally I would prefer an early wrong content type error message over the current behaviour. |
Description
Stupid people do stupid things. In my case I selected <application/javascript> as Content-Type in Postman instead of <application/json> and was wondering why the heck my code doesn't work as expected.... well, reason found. Anyway an error message which is a little more specific than the following one would have been nice.
Note: I only tested javascript vs. json header, the error is repeatable and it seems that the content of the json message is not relevant.
Relevant code snipped
Error message
Edit 2:
Golang structs:
Necessary request to trigger the stack overflow: Any, even an empty request body is enough.
The text was updated successfully, but these errors were encountered: