node/test/parallel/test-buffer-alloc-is-filled.js
Сковорода Никита Андреевич 25c5111ca4 src: avoid hanging on Buffer#fill 0-length input
Previously, zero-length Buffers and TypedArrays passed as fillers hanged
Buffer#fill and Buffer.from.

This changes those cases when it hanged to a zero-fill instead, which
should be backwards compatible.

This fixes CVE-2018-7167.

PR-URL: https://github.com/nodejs-private/node-private/pull/119
Fixes: https://github.com/nodejs-private/security/issues/193
Refs: https://github.com/nodejs-private/node-private/pull/118
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-06-11 17:52:46 -05:00

21 lines
412 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
for (const fill of [
'',
[],
Buffer.from(''),
new Uint8Array(0),
{ toString: () => '' },
{ toString: () => '', length: 10 }
]) {
for (let i = 0; i < 50; i++) {
const buf = Buffer.alloc(100, fill);
assert.strictEqual(buf.length, 100);
for (let n = 0; n < buf.length; n++)
assert.strictEqual(buf[n], 0);
}
}