From 2183283622030558bb1ec59007451cedcc0ac729 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Fri, 21 Jul 2023 02:42:37 +0800 Subject: [PATCH] http3: discard negative content-length header when writing response (#3983) * response writer: discard negative content-length header * shorten comment --------- Co-authored-by: Marten Seemann --- http3/response_writer.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/http3/response_writer.go b/http3/response_writer.go index 9fd40f72..d18c70be 100644 --- a/http3/response_writer.go +++ b/http3/response_writer.go @@ -64,9 +64,10 @@ func (w *responseWriter) WriteHeader(status int) { w.header.Set("Date", time.Now().UTC().Format(http.TimeFormat)) } // Content-Length checking + // use ParseUint instead of ParseInt, as negative values are invalid if clen := w.header.Get("Content-Length"); clen != "" { - if cl, err := strconv.ParseInt(clen, 10, 64); err == nil { - w.contentLen = cl + if cl, err := strconv.ParseUint(clen, 10, 63); err == nil { + w.contentLen = int64(cl) } else { // emit a warning for malformed Content-Length and remove it w.logger.Errorf("Malformed Content-Length %s", clen)