mirror of
https://github.com/gin-gonic/gin.git
synced 2026-09-05 07:02:15 +08:00
fix: limit request body size in Protobuf binder
This commit is contained in:
parent
c177562107
commit
49f4e069f2
@ -19,11 +19,14 @@ func (protobufBinding) Name() string {
|
||||
}
|
||||
|
||||
func (b protobufBinding) Bind(req *http.Request, obj any) error {
|
||||
buf, err := io.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(io.LimitReader(req.Body, MaxBodySize+1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.BindBody(buf, obj)
|
||||
if int64(len(body)) > MaxBodySize {
|
||||
return errors.New("request body too large")
|
||||
}
|
||||
return b.BindBody(body, obj)
|
||||
}
|
||||
|
||||
func (protobufBinding) BindBody(body []byte, obj any) error {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user