fix(server): return ErrMissingFile when MultipartForm.File is nil (#2260)

RequestCtx.FormFile previously returned (nil, nil) when the parsed
multipart form had a nil File map: the code returned the err variable
from the preceding successful MultipartForm() call, which is always
nil at that point. Callers checking `if err != nil` proceeded with a
nil *multipart.FileHeader, causing nil pointer dereferences downstream.

Return ErrMissingFile instead, matching the existing semantics for the
missing-key case immediately below. Fixes #2235.

Signed-off-by: Y.Horie <u5.horie@gmail.com>
This commit is contained in:
Y.Horie
2026-06-02 20:35:29 +09:00
committed by GitHub
parent a7d4e8d770
commit 46bfd1b9d8
+1 -1
View File
@@ -1145,7 +1145,7 @@ func (ctx *RequestCtx) FormFile(key string) (*multipart.FileHeader, error) {
return nil, err
}
if mf.File == nil {
return nil, err
return nil, ErrMissingFile
}
fhh := mf.File[key]
if fhh == nil {