@@ -210,10 +210,11 @@ Buffer.from = function from(value, encodingOrOffset, length) {
210210 ) ;
211211 }
212212
213- if ( typeof value === 'number' )
213+ if ( typeof value === 'number' ) {
214214 throw new errors . TypeError (
215215 'ERR_INVALID_ARG_TYPE' , 'value' , 'not number' , value
216216 ) ;
217+ }
217218
218219 const valueOf = value . valueOf && value . valueOf ( ) ;
219220 if ( valueOf !== null && valueOf !== undefined && valueOf !== value )
@@ -459,10 +460,11 @@ Buffer[kIsEncodingSymbol] = Buffer.isEncoding;
459460
460461Buffer . concat = function concat ( list , length ) {
461462 var i ;
462- if ( ! Array . isArray ( list ) )
463+ if ( ! Array . isArray ( list ) ) {
463464 throw new errors . TypeError (
464465 'ERR_INVALID_ARG_TYPE' , 'list' , [ 'Array' , 'Buffer' , 'Uint8Array' ]
465466 ) ;
467+ }
466468
467469 if ( list . length === 0 )
468470 return new FastBuffer ( ) ;
@@ -479,10 +481,11 @@ Buffer.concat = function concat(list, length) {
479481 var pos = 0 ;
480482 for ( i = 0 ; i < list . length ; i ++ ) {
481483 var buf = list [ i ] ;
482- if ( ! isUint8Array ( buf ) )
484+ if ( ! isUint8Array ( buf ) ) {
483485 throw new errors . TypeError (
484486 'ERR_INVALID_ARG_TYPE' , 'list' , [ 'Array' , 'Buffer' , 'Uint8Array' ]
485487 ) ;
488+ }
486489 _copy ( buf , buffer , pos ) ;
487490 pos += buf . length ;
488491 }
@@ -1036,13 +1039,23 @@ function checkOffset(offset, ext, length) {
10361039 throw new errors . RangeError ( 'ERR_INDEX_OUT_OF_RANGE' ) ;
10371040}
10381041
1042+ function checkByteLength ( byteLength ) {
1043+ if ( byteLength < 1 || byteLength > 6 ) {
1044+ throw new errors . RangeError ( 'ERR_OUT_OF_RANGE' ,
1045+ 'byteLength' ,
1046+ '>= 1 and <= 6' ) ;
1047+ }
1048+ }
1049+
10391050
10401051Buffer . prototype . readUIntLE =
10411052 function readUIntLE ( offset , byteLength , noAssert ) {
10421053 offset = offset >>> 0 ;
10431054 byteLength = byteLength >>> 0 ;
1044- if ( ! noAssert )
1055+ if ( ! noAssert ) {
1056+ checkByteLength ( byteLength ) ;
10451057 checkOffset ( offset , byteLength , this . length ) ;
1058+ }
10461059
10471060 var val = this [ offset ] ;
10481061 var mul = 1 ;
@@ -1058,8 +1071,10 @@ Buffer.prototype.readUIntBE =
10581071 function readUIntBE ( offset , byteLength , noAssert ) {
10591072 offset = offset >>> 0 ;
10601073 byteLength = byteLength >>> 0 ;
1061- if ( ! noAssert )
1074+ if ( ! noAssert ) {
1075+ checkByteLength ( byteLength ) ;
10621076 checkOffset ( offset , byteLength , this . length ) ;
1077+ }
10631078
10641079 var val = this [ offset + -- byteLength ] ;
10651080 var mul = 1 ;
@@ -1121,8 +1136,11 @@ Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
11211136Buffer . prototype . readIntLE = function readIntLE ( offset , byteLength , noAssert ) {
11221137 offset = offset >>> 0 ;
11231138 byteLength = byteLength >>> 0 ;
1124- if ( ! noAssert )
1139+
1140+ if ( ! noAssert ) {
1141+ checkByteLength ( byteLength ) ;
11251142 checkOffset ( offset , byteLength , this . length ) ;
1143+ }
11261144
11271145 var val = this [ offset ] ;
11281146 var mul = 1 ;
@@ -1141,8 +1159,11 @@ Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
11411159Buffer . prototype . readIntBE = function readIntBE ( offset , byteLength , noAssert ) {
11421160 offset = offset >>> 0 ;
11431161 byteLength = byteLength >>> 0 ;
1144- if ( ! noAssert )
1162+
1163+ if ( ! noAssert ) {
1164+ checkByteLength ( byteLength ) ;
11451165 checkOffset ( offset , byteLength , this . length ) ;
1166+ }
11461167
11471168 var i = byteLength ;
11481169 var mul = 1 ;
@@ -1624,9 +1645,10 @@ if (process.binding('config').hasIntl) {
16241645 // Transcodes the Buffer from one encoding to another, returning a new
16251646 // Buffer instance.
16261647 transcode = function transcode ( source , fromEncoding , toEncoding ) {
1627- if ( ! isUint8Array ( source ) )
1648+ if ( ! isUint8Array ( source ) ) {
16281649 throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , 'source' ,
16291650 [ 'Buffer' , 'Uint8Array' ] , source ) ;
1651+ }
16301652 if ( source . length === 0 ) return Buffer . alloc ( 0 ) ;
16311653
16321654 fromEncoding = normalizeEncoding ( fromEncoding ) || fromEncoding ;
0 commit comments