@@ -1036,33 +1036,33 @@ function addBufferPrototypeMethods(proto) {
1036
1036
proto . hexSlice = hexSlice ;
1037
1037
proto . ucs2Slice = ucs2Slice ;
1038
1038
proto . utf8Slice = utf8Slice ;
1039
- proto . asciiWrite = function ( string , offset = 0 , length = this . byteLength ) {
1039
+ proto . asciiWrite = function ( string , offset = 0 , length = this . byteLength - offset ) {
1040
1040
if ( offset < 0 || offset > this . byteLength ) {
1041
1041
throw new ERR_BUFFER_OUT_OF_BOUNDS ( 'offset' ) ;
1042
1042
}
1043
- if ( length < 0 ) {
1043
+ if ( length < 0 || length > this . byteLength - offset ) {
1044
1044
throw new ERR_BUFFER_OUT_OF_BOUNDS ( 'length' ) ;
1045
1045
}
1046
1046
return asciiWriteStatic ( this , string , offset , length ) ;
1047
1047
} ;
1048
1048
proto . base64Write = base64Write ;
1049
1049
proto . base64urlWrite = base64urlWrite ;
1050
- proto . latin1Write = function ( string , offset = 0 , length = this . byteLength ) {
1050
+ proto . latin1Write = function ( string , offset = 0 , length = this . byteLength - offset ) {
1051
1051
if ( offset < 0 || offset > this . byteLength ) {
1052
1052
throw new ERR_BUFFER_OUT_OF_BOUNDS ( 'offset' ) ;
1053
1053
}
1054
- if ( length < 0 ) {
1054
+ if ( length < 0 || length > this . byteLength - offset ) {
1055
1055
throw new ERR_BUFFER_OUT_OF_BOUNDS ( 'length' ) ;
1056
1056
}
1057
1057
return latin1WriteStatic ( this , string , offset , length ) ;
1058
1058
} ;
1059
1059
proto . hexWrite = hexWrite ;
1060
1060
proto . ucs2Write = ucs2Write ;
1061
- proto . utf8Write = function ( string , offset = 0 , length = this . byteLength ) {
1061
+ proto . utf8Write = function ( string , offset = 0 , length = this . byteLength - offset ) {
1062
1062
if ( offset < 0 || offset > this . byteLength ) {
1063
1063
throw new ERR_BUFFER_OUT_OF_BOUNDS ( 'offset' ) ;
1064
1064
}
1065
- if ( length < 0 ) {
1065
+ if ( length < 0 || length > this . byteLength - offset ) {
1066
1066
throw new ERR_BUFFER_OUT_OF_BOUNDS ( 'length' ) ;
1067
1067
}
1068
1068
return utf8WriteStatic ( this , string , offset , length ) ;
0 commit comments