Commit c954b18 1 parent 9e04f2c commit c954b18 Copy full SHA for c954b18
File tree 5 files changed +25
-25
lines changed
5 files changed +25
-25
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ const {
23
23
createBlobFromFilePath : _createBlobFromFilePath ,
24
24
getDataObject,
25
25
} = internalBinding ( 'blob' ) ;
26
+ const {
27
+ kMaxLength,
28
+ } = internalBinding ( 'buffer' ) ;
26
29
27
30
const {
28
31
TextDecoder,
@@ -61,7 +64,6 @@ const {
61
64
} = require ( 'internal/errors' ) ;
62
65
63
66
const {
64
- isUint32,
65
67
validateDictionary,
66
68
} = require ( 'internal/validators' ) ;
67
69
@@ -159,8 +161,8 @@ class Blob {
159
161
return src ;
160
162
} ) ;
161
163
162
- if ( ! isUint32 ( length ) )
163
- throw new ERR_BUFFER_TOO_LARGE ( 0xFFFFFFFF ) ;
164
+ if ( length > kMaxLength )
165
+ throw new ERR_BUFFER_TOO_LARGE ( kMaxLength ) ;
164
166
165
167
this [ kHandle ] = _createBlob ( sources_ , length ) ;
166
168
this [ kLength ] = length ;
Original file line number Diff line number Diff line change 3
3
4
4
const common = require ( '../common' ) ;
5
5
const assert = require ( 'assert' ) ;
6
- const { Blob } = require ( 'buffer' ) ;
6
+ const { Blob, kMaxLength } = require ( 'buffer' ) ;
7
7
8
8
if ( common . isFreeBSD )
9
9
common . skip ( 'Oversized buffer make the FreeBSD CI runner crash' ) ;
10
10
11
11
try {
12
- new Blob ( [ new Uint8Array ( 0xffffffff ) , [ 1 ] ] ) ;
12
+ new Blob ( [ new Uint8Array ( kMaxLength ) , [ 1 ] ] ) ;
13
13
} catch ( e ) {
14
14
if (
15
15
e . message === 'Array buffer allocation failed' ||
16
- e . message === ' Invalid typed array length: 4294967295'
16
+ e . message === ` Invalid typed array length: ${ kMaxLength } `
17
17
) {
18
18
common . skip (
19
19
'Insufficient memory on this platform for oversized buffer test.'
Original file line number Diff line number Diff line change @@ -4,13 +4,16 @@ const common = require('../common');
4
4
const assert = require ( 'assert' ) ;
5
5
const vm = require ( 'vm' ) ;
6
6
7
- const SlowBuffer = require ( 'buffer' ) . SlowBuffer ;
7
+ const {
8
+ SlowBuffer,
9
+ kMaxLength,
10
+ } = require ( 'buffer' ) ;
8
11
9
12
// Verify the maximum Uint8Array size. There is no concrete limit by spec. The
10
13
// internal limits should be updated if this fails.
11
14
assert . throws (
12
- ( ) => new Uint8Array ( 2 ** 32 + 1 ) ,
13
- { message : ' Invalid typed array length: 4294967297' }
15
+ ( ) => new Uint8Array ( kMaxLength + 1 ) ,
16
+ { message : ` Invalid typed array length: ${ kMaxLength + 1 } ` } ,
14
17
) ;
15
18
16
19
const b = Buffer . allocUnsafe ( 1024 ) ;
Original file line number Diff line number Diff line change @@ -12,18 +12,8 @@ const bufferMaxSizeMsg = {
12
12
name : 'RangeError' ,
13
13
} ;
14
14
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
-
21
15
assert . throws ( ( ) => Buffer ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
22
16
assert . throws ( ( ) => SlowBuffer ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
23
17
assert . throws ( ( ) => Buffer . alloc ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
24
18
assert . throws ( ( ) => Buffer . allocUnsafe ( kMaxLength + 1 ) , bufferMaxSizeMsg ) ;
25
19
assert . 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 1
1
'use strict' ;
2
2
require ( '../common' ) ;
3
3
4
- // This test ensures that Node.js throws a RangeError when trying to convert a
5
- // gigantic buffer into a string.
4
+ // This test ensures that Node.js throws an Error when trying to convert a
5
+ // large buffer into a string.
6
6
// Regression test for https://github.com/nodejs/node/issues/649.
7
7
8
8
const assert = require ( 'assert' ) ;
9
- const SlowBuffer = require ( 'buffer' ) . SlowBuffer ;
9
+ const {
10
+ SlowBuffer,
11
+ constants : {
12
+ MAX_STRING_LENGTH ,
13
+ } ,
14
+ } = require ( 'buffer' ) ;
10
15
11
- const len = 1422561062959 ;
16
+ const len = MAX_STRING_LENGTH + 1 ;
12
17
const message = {
13
- code : 'ERR_OUT_OF_RANGE ' ,
14
- name : 'RangeError ' ,
18
+ code : 'ERR_STRING_TOO_LONG ' ,
19
+ name : 'Error ' ,
15
20
} ;
16
21
assert . throws ( ( ) => Buffer ( len ) . toString ( 'utf8' ) , message ) ;
17
22
assert . throws ( ( ) => SlowBuffer ( len ) . toString ( 'utf8' ) , message ) ;
You can’t perform that action at this time.
0 commit comments