@@ -51,34 +51,46 @@ read(buf, 'readUInt32LE', [1], 0xcfea48fd);
5151read ( buf , 'readUIntBE' , [ 2 , 2 ] , 0x48ea ) ;
5252read ( buf , 'readUIntLE' , [ 2 , 2 ] , 0xea48 ) ;
5353
54+ // Error name and message
55+ const OOR_ERROR =
56+ {
57+ name : 'RangeError [ERR_OUT_OF_RANGE]'
58+ } ;
59+
60+ const OOB_ERROR =
61+ {
62+ name : 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]' ,
63+ message : 'Attempt to write outside buffer bounds'
64+ } ;
65+
5466// Attempt to overflow buffers, similar to previous bug in array buffers
55- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . readFloatBE ( 0xffffffff ) ,
56- RangeError ) ;
57- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . readFloatLE ( 0xffffffff ) ,
58- RangeError ) ;
67+ assert . throws (
68+ ( ) => Buffer . allocUnsafe ( 8 ) . readFloatBE ( 0xffffffff ) , OOR_ERROR ) ;
69+
70+ assert . throws (
71+ ( ) => Buffer . allocUnsafe ( 8 ) . readFloatLE ( 0xffffffff ) , OOR_ERROR ) ;
5972
6073// Ensure negative values can't get past offset
61- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . readFloatBE ( - 1 ) , RangeError ) ;
62- assert . throws ( ( ) => Buffer . allocUnsafe ( 8 ) . readFloatLE ( - 1 ) , RangeError ) ;
74+ assert . throws (
75+ ( ) => Buffer . allocUnsafe ( 8 ) . readFloatBE ( - 1 ) , OOR_ERROR ) ;
76+ assert . throws (
77+ ( ) => Buffer . allocUnsafe ( 8 ) . readFloatLE ( - 1 ) , OOR_ERROR ) ;
6378
6479// Offset checks
6580{
6681 const buf = Buffer . allocUnsafe ( 0 ) ;
6782
68- assert . throws ( ( ) => buf . readUInt8 ( 0 ) , RangeError ) ;
69- assert . throws ( ( ) => buf . readInt8 ( 0 ) , RangeError ) ;
83+ assert . throws (
84+ ( ) => buf . readUInt8 ( 0 ) , OOB_ERROR ) ;
85+ assert . throws (
86+ ( ) => buf . readInt8 ( 0 ) , OOB_ERROR ) ;
7087}
7188
7289[ 16 , 32 ] . forEach ( ( bit ) => {
7390 const buf = Buffer . allocUnsafe ( bit / 8 - 1 ) ;
7491 [ `Int${ bit } B` , `Int${ bit } L` , `UInt${ bit } B` , `UInt${ bit } L` ] . forEach ( ( fn ) => {
7592 assert . throws (
76- ( ) => buf [ `read${ fn } E` ] ( 0 ) ,
77- {
78- name : 'RangeError [ERR_BUFFER_OUT_OF_BOUNDS]' ,
79- message : 'Attempt to write outside buffer bounds'
80- }
81- ) ;
93+ ( ) => buf [ `read${ fn } E` ] ( 0 ) , OOB_ERROR ) ;
8294 } ) ;
8395} ) ;
8496
0 commit comments