Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
617ee32
src: fix memory leak in ExternString
skomski Aug 16, 1970
56d9584
child_process: add callback parameter to .send()
bnoordhuis Aug 30, 2015
abbc8db
test: mark eval_messages as flaky
orangemocha Sep 2, 2015
6ce8f5f
doc: reorder collaborators by their usernames
jbergstroem Jul 25, 2015
47e5cf7
doc: update url doc to account for escaping
Fishrock123 Aug 28, 2015
8ca9ea2
test: refactor to eliminate flaky test
Trott Aug 29, 2015
107cbd6
child_process: check execFile and fork args
jasnell Sep 2, 2015
4a1b519
build: add --enable-asan with builtin leakcheck
skomski Aug 14, 2015
b513a33
events,lib: don't require EE#listenerCount()
Fishrock123 Sep 2, 2015
1134188
deps: upgrade V8 to 4.5.103.24
ofrobots Aug 23, 2015
a7392ff
src: apply debug force load fixups from 41e63fb
ofrobots Aug 23, 2015
709ed15
contextify: ignore getters during initialization
indutny Jul 7, 2015
06f38de
test: fix test-repl-tab-complete.js for V8 4.5
ofrobots Aug 23, 2015
39aa573
src: enable v8 deprecation warnings and fix them
bnoordhuis Jul 1, 2015
d08bb97
src: replace usage of v8::Handle with v8::Local
targos Jul 18, 2015
564e214
src: enable vector ics on arm again
ofrobots Aug 23, 2015
074315f
src: re-enable fast math on arm
targos Aug 28, 2015
64beab0
deps: upgrade V8 to 4.5.103.30
ofrobots Sep 1, 2015
fc66eed
test: fix use of `common` before required
rvagg Sep 4, 2015
eefe14c
buffer: SlowBuffer only accept valid numeric values
targos Sep 1, 2015
a338eb3
doc,test: enable recursive file watching in Windows
thefourtheye Sep 2, 2015
80bcab9
src: fix buffer overflow for long exception lines
skomski Sep 3, 2015
3a731da
src: use standard conform snprintf on windows
skomski Sep 3, 2015
a6cb3a5
doc: update environment vars in manpage and --help
silverwind Sep 4, 2015
880410d
doc: add TSC meeting minutes 2015-09-02
rvagg Sep 3, 2015
63a628d
build: fix .pkg creation tooling
rvagg Sep 4, 2015
d0c682a
deps: backport 75e43a6 from v8 upstream (again)
Aug 11, 2015
50717a6
build: make .msi install to "nodejs", not "node"
rvagg Sep 5, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
buffer: SlowBuffer only accept valid numeric values
Fixes a regression that appeared with the new Buffer implementation in v3.
Without this change, calling the SlowBuffer constructor with something else
than a number would abort on the C++ side. This makes sure that the length
argument is coerced to number or is 0.

Fixes: #2634
PR-URL: #2635
Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
Reviewed-By: cjihrig - Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
targos committed Sep 4, 2015
commit eefe14c5ff3e911ab7a41b913b910d8c405ad8cd
4 changes: 2 additions & 2 deletions lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ createPool();


function SlowBuffer(length) {
if (length < 0)
if (+length != length)
length = 0;
return binding.create(length);
return binding.create(+length);
};

SlowBuffer.prototype.__proto__ = Buffer.prototype;
Expand Down
55 changes: 55 additions & 0 deletions test/parallel/test-buffer-slow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const buffer = require('buffer');
const Buffer = buffer.Buffer;
const SlowBuffer = buffer.SlowBuffer;

const ones = [1, 1, 1, 1];

// should create a Buffer
let sb = new SlowBuffer(4);
assert(sb instanceof Buffer);
assert.strictEqual(sb.length, 4);
sb.fill(1);
assert.deepEqual(sb, ones);

// underlying ArrayBuffer should have the same length
assert.strictEqual(sb.buffer.byteLength, 4);

// should work without new
sb = SlowBuffer(4);
assert(sb instanceof Buffer);
assert.strictEqual(sb.length, 4);
sb.fill(1);
assert.deepEqual(sb, ones);

// should work with edge cases
assert.strictEqual(SlowBuffer(0).length, 0);
try {
assert.strictEqual(SlowBuffer(buffer.kMaxLength).length, buffer.kMaxLength);
} catch (e) {
assert.equal(e.message, 'Buffer allocation failed - process out of memory');
}

// should work with number-coercible values
assert.strictEqual(SlowBuffer('6').length, 6);
assert.strictEqual(SlowBuffer(true).length, 1);

// should create zero-length buffer if parameter is not a number
assert.strictEqual(SlowBuffer().length, 0);
assert.strictEqual(SlowBuffer(NaN).length, 0);
assert.strictEqual(SlowBuffer({}).length, 0);
assert.strictEqual(SlowBuffer('string').length, 0);

// should throw with invalid length
assert.throws(function() {
new SlowBuffer(Infinity);
}, 'invalid Buffer length');
assert.throws(function() {
new SlowBuffer(-1);
}, 'invalid Buffer length');
assert.throws(function() {
new SlowBuffer(buffer.kMaxLength + 1);
}, 'invalid Buffer length');