-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buffer: consistent error for length > kMaxLength
- Always return the same error message(hopefully more informative) for buffer length > kMaxLength and avoid getting into V8 C++ land for unnecessary checks. - Use accurate RegExp(reusable as `common.bufferMaxSizeMsg`) in tests for this error. - Separate related tests from test-buffer-alloc. PR-URL: #10152 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
8329605
commit 3d353c7
Showing
6 changed files
with
49 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const buffer = require('buffer'); | ||
const Buffer = buffer.Buffer; | ||
const SlowBuffer = buffer.SlowBuffer; | ||
|
||
const kMaxLength = buffer.kMaxLength; | ||
const bufferMaxSizeMsg = common.bufferMaxSizeMsg; | ||
|
||
assert.throws(() => Buffer((-1 >>> 0) + 1), bufferMaxSizeMsg); | ||
assert.throws(() => SlowBuffer((-1 >>> 0) + 1), bufferMaxSizeMsg); | ||
assert.throws(() => Buffer.alloc((-1 >>> 0) + 1), bufferMaxSizeMsg); | ||
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 1), bufferMaxSizeMsg); | ||
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 1), bufferMaxSizeMsg); | ||
|
||
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg); | ||
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg); | ||
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg); | ||
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg); | ||
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg); | ||
|
||
// issue GH-4331 | ||
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFF), bufferMaxSizeMsg); | ||
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFFF), bufferMaxSizeMsg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const SlowBuffer = require('buffer').SlowBuffer; | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/649. | ||
const len = 1422561062959; | ||
const lenLimitMsg = new RegExp('^RangeError: (Invalid typed array length' + | ||
'|Array buffer allocation failed' + | ||
'|Invalid array buffer length)$'); | ||
|
||
assert.throws(() => Buffer(len).toString('utf8'), lenLimitMsg); | ||
assert.throws(() => SlowBuffer(len).toString('utf8'), lenLimitMsg); | ||
assert.throws(() => Buffer.alloc(len).toString('utf8'), lenLimitMsg); | ||
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), lenLimitMsg); | ||
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), | ||
lenLimitMsg); | ||
const message = common.bufferMaxSizeMsg; | ||
assert.throws(() => Buffer(len).toString('utf8'), message); | ||
assert.throws(() => SlowBuffer(len).toString('utf8'), message); | ||
assert.throws(() => Buffer.alloc(len).toString('utf8'), message); | ||
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message); | ||
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters