@@ -28,6 +28,21 @@ const { headerNameLowerCasedRecord } = require('./constants')
2828// Verifies that a given path is valid does not contain control chars \x00 to \x20
2929const invalidPathRegex = / [ ^ \u0021 - \u00ff ] /
3030
31+ function isValidContentLengthHeaderValue ( val ) {
32+ if ( typeof val !== 'string' || val . length === 0 ) {
33+ return false
34+ }
35+
36+ for ( let i = 0 ; i < val . length ; i ++ ) {
37+ const charCode = val . charCodeAt ( i )
38+ if ( charCode < 48 || charCode > 57 ) {
39+ return false
40+ }
41+ }
42+
43+ return true
44+ }
45+
3146const kHandler = Symbol ( 'handler' )
3247const kController = Symbol ( 'controller' )
3348const kResume = Symbol ( 'resume' )
@@ -484,10 +499,10 @@ function processHeader (request, key, val) {
484499 if ( request . contentLength !== null ) {
485500 throw new InvalidArgumentError ( 'duplicate content-length header' )
486501 }
487- request . contentLength = parseInt ( val , 10 )
488- if ( ! Number . isFinite ( request . contentLength ) ) {
502+ if ( ! isValidContentLengthHeaderValue ( val ) ) {
489503 throw new InvalidArgumentError ( 'invalid content-length header' )
490504 }
505+ request . contentLength = parseInt ( val , 10 )
491506 } else if ( request . contentType === null && headerName === 'content-type' ) {
492507 request . contentType = val
493508 request . headers . push ( key , val )
0 commit comments