fix(volume): avoid panic when URL path has a dot before the comma (#9712)

LastIndex returns -1 when the separator is missing and can return any
position when both are present. A path like /vol/file.jpg,abc gives
dotSep<commaSep, so path[commaSep+1:dotSep] slices with start>end and
panics. Only treat the dot as an extension boundary when it sits after
the comma.
This commit is contained in:
Chris Lu
2026-05-27 11:29:11 -07:00
committed by GitHub
parent 65d557cbb0
commit c3255b51fd

View File

@@ -110,7 +110,8 @@ func CreateNeedleFromRequest(r *http.Request, fixJpgOrientation bool, sizeLimit
commaSep := strings.LastIndex(r.URL.Path, ",")
dotSep := strings.LastIndex(r.URL.Path, ".")
fid := r.URL.Path[commaSep+1:]
if dotSep > 0 {
// dot must be after comma; otherwise path[commaSep+1:dotSep] panics
if dotSep > commaSep {
fid = r.URL.Path[commaSep+1 : dotSep]
}