From 0d0009ed1f9da087cd7541e453d9db3ace47a7fc Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Wed, 5 Aug 2026 00:47:28 +0800 Subject: [PATCH] fix: limit request body size in Protobuf binding --- binding/protobuf.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/binding/protobuf.go b/binding/protobuf.go index 259ae8e7..0e522722 100644 --- a/binding/protobuf.go +++ b/binding/protobuf.go @@ -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) }