@@ -51,34 +51,46 @@ read(buf, 'readUInt32LE', [1], 0xcfea48fd);
51
51
read ( buf , 'readUIntBE' , [ 2 , 2 ] , 0x48ea ) ;
52
52
read ( buf , 'readUIntLE' , [ 2 , 2 ] , 0xea48 ) ;
53
53
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
+
54
66
// 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 ) ;
59
72
60
73
// 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 ) ;
63
78
64
79
// Offset checks
65
80
{
66
81
const buf = Buffer . allocUnsafe ( 0 ) ;
67
82
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 ) ;
70
87
}
71
88
72
89
[ 16 , 32 ] . forEach ( ( bit ) => {
73
90
const buf = Buffer . allocUnsafe ( bit / 8 - 1 ) ;
74
91
[ `Int${ bit } B` , `Int${ bit } L` , `UInt${ bit } B` , `UInt${ bit } L` ] . forEach ( ( fn ) => {
75
92
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 ) ;
82
94
} ) ;
83
95
} ) ;
84
96
0 commit comments