aboutsummaryrefslogtreecommitdiff
path: root/src/mime/multipart/formdata.go
diff options
context:
space:
mode:
authorhopehook <hopehook@qq.com>2023-02-12 22:27:35 +0800
committerGopher Robot <gobot@golang.org>2023-02-28 17:49:22 +0000
commitd61ae9ded4ebc142fb0edccfee893fa10c233357 (patch)
tree7fc0ee4609eda24e21022016973dff3a1e0c8f0f /src/mime/multipart/formdata.go
parenteee2697c38b73b731604d5584abd97bf674857ed (diff)
downloadgo-d61ae9ded4ebc142fb0edccfee893fa10c233357.tar.xz
mime/multipart: fix Reader.ReadForm(math.MaxInt64) overflow
Because "CopyN" will read one more byte, which will cause us to overflow when calling "Reader.ReadForm(math.MaxInt64)". So we should check if the parameter exceeds "math.MaxInt64" to avoid returning no data. Fixes #58384. Change-Id: I30088ce6468176b21e4a9a0b8b6080f2986dda23 Reviewed-on: https://go-review.googlesource.com/c/go/+/467557 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Run-TryBot: hopehook <hopehook@golangcn.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/mime/multipart/formdata.go')
-rw-r--r--src/mime/multipart/formdata.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/mime/multipart/formdata.go b/src/mime/multipart/formdata.go
index 41bc886d16..e62727dbb1 100644
--- a/src/mime/multipart/formdata.go
+++ b/src/mime/multipart/formdata.go
@@ -77,6 +77,9 @@ func (r *Reader) readForm(maxMemory int64) (_ *Form, err error) {
// unconfigurable 10 MB added on to maxMemory, is unfortunate but difficult to change
// within the constraints of the API as documented.
maxFileMemoryBytes := maxMemory
+ if maxFileMemoryBytes == math.MaxInt64 {
+ maxFileMemoryBytes--
+ }
maxMemoryBytes := maxMemory + int64(10<<20)
if maxMemoryBytes <= 0 {
if maxMemory < 0 {