http3: discard negative content-length header when writing response (#3983)

* response writer: discard negative content-length header

* shorten comment

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
WeidiDeng 2023-07-21 02:42:37 +08:00 committed by GitHub
parent 5a22ac8970
commit 2183283622
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)