fix: limit request body size in Protobuf binder

This commit is contained in:
water 2026-07-29 11:24:52 +08:00
parent c177562107
commit 49f4e069f2

View File

@ -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 {