mirror of
https://github.com/gin-gonic/gin.git
synced 2026-11-23 11:33:37 +08:00
fix: limit request body size in Protobuf binding
This commit is contained in:
parent
3b3f352fa6
commit
0d0009ed1f
@ -19,10 +19,13 @@ func (protobufBinding) Name() string {
|
||||
}
|
||||
|
||||
func (b protobufBinding) Bind(req *http.Request, obj any) error {
|
||||
buf, err := io.ReadAll(req.Body)
|
||||
buf, err := io.ReadAll(io.LimitReader(req.Body, DefaultMaxBodySize+1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(buf) > DefaultMaxBodySize {
|
||||
return http.ErrBodyReadAfterClose
|
||||
}
|
||||
return b.BindBody(buf, obj)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user