Skip to content

Commit 1948d37

Browse files
authored
buffer: check INSPECT_MAX_BYTES with validateNumber
PR-URL: #46599 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 9a31ac1 commit 1948d37

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/buffer.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,10 @@ ObjectDefineProperties(module.exports, {
14011401
configurable: true,
14021402
enumerable: true,
14031403
get() { return INSPECT_MAX_BYTES; },
1404-
set(val) { INSPECT_MAX_BYTES = val; },
1404+
set(val) {
1405+
validateNumber(val, 'INSPECT_MAX_BYTES', 0);
1406+
INSPECT_MAX_BYTES = val;
1407+
},
14051408
},
14061409
});
14071410

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const buffer = require('buffer');
6+
7+
const rangeErrorObjs = [NaN, -1];
8+
const typeErrorObj = 'and even this';
9+
10+
for (const obj of rangeErrorObjs) {
11+
assert.throws(
12+
() => buffer.INSPECT_MAX_BYTES = obj,
13+
{
14+
code: 'ERR_OUT_OF_RANGE',
15+
name: 'RangeError',
16+
}
17+
);
18+
19+
assert.throws(
20+
() => buffer.INSPECT_MAX_BYTES = obj,
21+
{
22+
code: 'ERR_OUT_OF_RANGE',
23+
name: 'RangeError',
24+
}
25+
);
26+
}
27+
28+
assert.throws(
29+
() => buffer.INSPECT_MAX_BYTES = typeErrorObj,
30+
{
31+
code: 'ERR_INVALID_ARG_TYPE',
32+
name: 'TypeError',
33+
}
34+
);

0 commit comments

Comments
 (0)