@@ -55,6 +55,23 @@ func TestReadFormWithNamelessFile(t *testing.T) {
55
55
}
56
56
}
57
57
58
+ // Issue 58384: Handle ReadForm(math.MaxInt64)
59
+ func TestReadFormWitFileNameMaxMemoryOverflow (t * testing.T ) {
60
+ b := strings .NewReader (strings .ReplaceAll (messageWithFileName , "\n " , "\r \n " ))
61
+ r := NewReader (b , boundary )
62
+ f , err := r .ReadForm (math .MaxInt64 )
63
+ if err != nil {
64
+ t .Fatalf ("ReadForm(MaxInt64): %v" , err )
65
+ }
66
+ defer f .RemoveAll ()
67
+
68
+ fd := testFile (t , f .File ["filea" ][0 ], "filea.txt" , fileaContents )
69
+ if _ , ok := fd .(* os.File ); ok {
70
+ t .Error ("file is *os.File, should not be" )
71
+ }
72
+ fd .Close ()
73
+ }
74
+
58
75
// Issue 40430: Handle ReadForm(math.MaxInt64)
59
76
func TestReadFormMaxMemoryOverflow (t * testing.T ) {
60
77
b := strings .NewReader (strings .ReplaceAll (messageWithTextContentType , "\n " , "\r \n " ))
@@ -66,6 +83,11 @@ func TestReadFormMaxMemoryOverflow(t *testing.T) {
66
83
if f == nil {
67
84
t .Fatal ("ReadForm(MaxInt64): missing form" )
68
85
}
86
+ defer f .RemoveAll ()
87
+
88
+ if g , e := f .Value ["texta" ][0 ], textaValue ; g != e {
89
+ t .Errorf ("texta value = %q, want %q" , g , e )
90
+ }
69
91
}
70
92
71
93
func TestReadFormWithTextContentType (t * testing.T ) {
@@ -122,6 +144,15 @@ Content-Type: text/plain
122
144
--MyBoundary--
123
145
`
124
146
147
+ const messageWithFileName = `
148
+ --MyBoundary
149
+ Content-Disposition: form-data; name="filea"; filename="filea.txt"
150
+ Content-Type: text/plain
151
+
152
+ ` + fileaContents + `
153
+ --MyBoundary--
154
+ `
155
+
125
156
const messageWithTextContentType = `
126
157
--MyBoundary
127
158
Content-Disposition: form-data; name="texta"
0 commit comments