File tree Expand file tree Collapse file tree 3 files changed +16
-23
lines changed Expand file tree Collapse file tree 3 files changed +16
-23
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,6 @@ const vm = require('vm');
66
77const SlowBuffer = require ( 'buffer' ) . SlowBuffer ;
88
9- // Verify the maximum Uint8Array size. There is no concrete limit by spec. The
10- // internal limits should be updated if this fails.
11- assert . throws (
12- ( ) => new Uint8Array ( 2 ** 32 + 1 ) ,
13- { message : 'Invalid typed array length: 4294967297' }
14- ) ;
15-
169const b = Buffer . allocUnsafe ( 1024 ) ;
1710assert . strictEqual ( b . length , 1024 ) ;
1811
Original file line number Diff line number Diff line change @@ -12,18 +12,8 @@ const bufferMaxSizeMsg = {
1212 name : 'RangeError' ,
1313} ;
1414
15- assert . throws ( ( ) => Buffer ( ( - 1 >>> 0 ) + 2 ) , bufferMaxSizeMsg ) ;
16- assert . throws ( ( ) => SlowBuffer ( ( - 1 >>> 0 ) + 2 ) , bufferMaxSizeMsg ) ;
17- assert . throws ( ( ) => Buffer . alloc ( ( - 1 >>> 0 ) + 2 ) , bufferMaxSizeMsg ) ;
18- assert . throws ( ( ) => Buffer . allocUnsafe ( ( - 1 >>> 0 ) + 2 ) , bufferMaxSizeMsg ) ;
19- assert . throws ( ( ) => Buffer . allocUnsafeSlow ( ( - 1 >>> 0 ) + 2 ) , bufferMaxSizeMsg ) ;
20-
2115assert . throws ( ( ) => Buffer ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
2216assert . throws ( ( ) => SlowBuffer ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
2317assert . throws ( ( ) => Buffer . alloc ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
2418assert . throws ( ( ) => Buffer . allocUnsafe ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
2519assert . throws ( ( ) => Buffer . allocUnsafeSlow ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
26-
27- // issue GH-4331
28- assert . throws ( ( ) => Buffer . allocUnsafe ( 0x100000001 ) , bufferMaxSizeMsg ) ;
29- assert . throws ( ( ) => Buffer . allocUnsafe ( 0xFFFFFFFFF ) , bufferMaxSizeMsg ) ;
Original file line number Diff line number Diff line change @@ -8,13 +8,23 @@ require('../common');
88const assert = require ( 'assert' ) ;
99const SlowBuffer = require ( 'buffer' ) . SlowBuffer ;
1010
11- const len = 1422561062959 ;
11+ // Find the maximum supported buffer length.
12+ let limit = 1 << 31 ; // 2GB
13+ while ( true ) {
14+ try {
15+ Buffer ( limit ) ;
16+ limit *= 2 ;
17+ } catch ( e ) {
18+ break ;
19+ }
20+ }
21+
1222const message = {
1323 code : 'ERR_OUT_OF_RANGE' ,
1424 name : 'RangeError' ,
1525} ;
16- assert . throws ( ( ) => Buffer ( len ) . toString ( 'utf8' ) , message ) ;
17- assert . throws ( ( ) => SlowBuffer ( len ) . toString ( 'utf8' ) , message ) ;
18- assert . throws ( ( ) => Buffer . alloc ( len ) . toString ( 'utf8' ) , message ) ;
19- assert . throws ( ( ) => Buffer . allocUnsafe ( len ) . toString ( 'utf8' ) , message ) ;
20- assert . throws ( ( ) => Buffer . allocUnsafeSlow ( len ) . toString ( 'utf8' ) , message ) ;
26+ assert . throws ( ( ) => Buffer ( limit ) . toString ( 'utf8' ) , message ) ;
27+ assert . throws ( ( ) => SlowBuffer ( limit ) . toString ( 'utf8' ) , message ) ;
28+ assert . throws ( ( ) => Buffer . alloc ( limit ) . toString ( 'utf8' ) , message ) ;
29+ assert . throws ( ( ) => Buffer . allocUnsafe ( limit ) . toString ( 'utf8' ) , message ) ;
30+ assert . throws ( ( ) => Buffer . allocUnsafeSlow ( limit ) . toString ( 'utf8' ) , message ) ;
You can’t perform that action at this time.
0 commit comments