mirror of https://github.com/lukechilds/node.git
Browse Source
- 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: https://github.com/nodejs/node/pull/10152 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>v6
Joyee Cheung
8 years ago
committed by
Anna Henningsen
6 changed files with 49 additions and 26 deletions
@ -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); |
@ -1,18 +1,14 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
|
||||
require('../common'); |
const common = require('../common'); |
||||
const assert = require('assert'); |
const assert = require('assert'); |
||||
const SlowBuffer = require('buffer').SlowBuffer; |
const SlowBuffer = require('buffer').SlowBuffer; |
||||
|
|
||||
// Regression test for https://github.com/nodejs/node/issues/649.
|
// Regression test for https://github.com/nodejs/node/issues/649.
|
||||
const len = 1422561062959; |
const len = 1422561062959; |
||||
const lenLimitMsg = new RegExp('^RangeError: (Invalid typed array length' + |
const message = common.bufferMaxSizeMsg; |
||||
'|Array buffer allocation failed' + |
assert.throws(() => Buffer(len).toString('utf8'), message); |
||||
'|Invalid array buffer length)$'); |
assert.throws(() => SlowBuffer(len).toString('utf8'), message); |
||||
|
assert.throws(() => Buffer.alloc(len).toString('utf8'), message); |
||||
assert.throws(() => Buffer(len).toString('utf8'), lenLimitMsg); |
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), message); |
||||
assert.throws(() => SlowBuffer(len).toString('utf8'), lenLimitMsg); |
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), message); |
||||
assert.throws(() => Buffer.alloc(len).toString('utf8'), lenLimitMsg); |
|
||||
assert.throws(() => Buffer.allocUnsafe(len).toString('utf8'), lenLimitMsg); |
|
||||
assert.throws(() => Buffer.allocUnsafeSlow(len).toString('utf8'), |
|
||||
lenLimitMsg); |
|
||||
|
Loading…
Reference in new issue