Skip to content

Commit fda56b9

Browse files
gurgundayaduh95
authored andcommitted
lib: limit split function calls to prevent excessive array length
PR-URL: #57501 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
1 parent 4b04c92 commit fda56b9

File tree

12 files changed

+12
-11
lines changed

12 files changed

+12
-11
lines changed

lib/internal/blob.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ function resolveObjectURL(url) {
360360
try {
361361
const parsed = new URL(url);
362362

363-
const split = StringPrototypeSplit(parsed.pathname, ':');
363+
const split = StringPrototypeSplit(parsed.pathname, ':', 3);
364364

365365
if (split.length !== 2)
366366
return;

lib/internal/debugger/inspect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class NodeInspector {
160160
this[domain] = createAgentProxy(domain, this.client);
161161
});
162162
this.handleDebugEvent = (fullName, params) => {
163-
const { 0: domain, 1: name } = StringPrototypeSplit(fullName, '.');
163+
const { 0: domain, 1: name } = StringPrototypeSplit(fullName, '.', 2);
164164
if (domain in this) {
165165
this[domain].emit(name, params);
166166
}

lib/internal/errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ const fatalExceptionStackEnhancers = {
907907
// ANSI escape sequences is not reliable.
908908
if (isWindows) {
909909
const info = internalBinding('os').getOSInformation();
910-
const ver = ArrayPrototypeMap(StringPrototypeSplit(info[2], '.'),
910+
const ver = ArrayPrototypeMap(StringPrototypeSplit(info[2], '.', 3),
911911
Number);
912912
if (ver[0] !== 10 || ver[2] < 14393) {
913913
useColors = false;

lib/internal/modules/cjs/loader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ function reconstructErrorStack(err, parentPath, parentSource) {
18331833
const { 1: line, 2: col } =
18341834
RegExpPrototypeExec(/(\d+):(\d+)\)/, errLine) || [];
18351835
if (line && col) {
1836-
const srcLine = StringPrototypeSplit(parentSource, '\n')[line - 1];
1836+
const srcLine = StringPrototypeSplit(parentSource, '\n', line)[line - 1];
18371837
const frame = `${parentPath}:${line}\n${srcLine}\n${StringPrototypeRepeat(' ', col - 1)}^\n`;
18381838
setArrowMessage(err, frame);
18391839
}

lib/internal/modules/esm/module_job.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class ModuleJob extends ModuleJobBase {
190190
if (!getSourceMapsSupport().enabled &&
191191
StringPrototypeIncludes(e.message,
192192
' does not provide an export named')) {
193-
const splitStack = StringPrototypeSplit(e.stack, '\n');
193+
const splitStack = StringPrototypeSplit(e.stack, '\n', 2);
194194
const parentFileUrl = RegExpPrototypeSymbolReplace(
195195
/:\d+$/,
196196
splitStack[0],

lib/internal/repl/await.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function processTopLevelAwait(src) {
178178
return null;
179179
const line = e.loc.line;
180180
const column = line === 1 ? e.loc.column - wrapPrefix.length : e.loc.column;
181-
let message = '\n' + StringPrototypeSplit(src, '\n')[line - 1] + '\n' +
181+
let message = '\n' + StringPrototypeSplit(src, '\n', line)[line - 1] + '\n' +
182182
StringPrototypeRepeat(' ', column) +
183183
'^\n\n' + RegExpPrototypeSymbolReplace(/ \([^)]+\)/, e.message, '');
184184
// V8 unexpected token errors include the token string.

lib/internal/source_map/source_map_cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function sourceMapFromFile(mapURL) {
292292
// data:[<mediatype>][;base64],<data> see:
293293
// https://tools.ietf.org/html/rfc2397#section-2
294294
function sourceMapFromDataUrl(sourceURL, url) {
295-
const { 0: format, 1: data } = StringPrototypeSplit(url, ',');
295+
const { 0: format, 1: data } = StringPrototypeSplit(url, ',', 2);
296296
const splitFormat = StringPrototypeSplit(format, ';');
297297
const contentType = splitFormat[0];
298298
const base64 = splitFormat[splitFormat.length - 1] === 'base64';

lib/internal/test_runner/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ function parseCommandLine() {
263263
);
264264
}
265265

266-
const indexAndTotal = StringPrototypeSplit(shardOption, '/');
266+
const indexAndTotal = StringPrototypeSplit(shardOption, '/', 2);
267267
shard = {
268268
__proto__: null,
269269
index: NumberParseInt(indexAndTotal[0], 10),

lib/internal/tty.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function getColorDepth(env = process.env) {
138138
// Lazy load for startup performance.
139139
if (OSRelease === undefined) {
140140
const { release } = require('os');
141-
OSRelease = StringPrototypeSplit(release(), '.');
141+
OSRelease = StringPrototypeSplit(release(), '.', 3);
142142
}
143143
// Windows 10 build 10586 is the first Windows release that supports 256
144144
// colors. Windows 10 build 14931 is the first release that supports

lib/internal/util/debuglog.js

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ function formatTime(ms) {
160160
({ 0: seconds, 1: ms } = StringPrototypeSplit(
161161
NumberPrototypeToFixed(seconds, 3),
162162
'.',
163+
2,
163164
));
164165
const res = hours !== 0 ? `${hours}:${pad(minutes)}` : minutes;
165166
return `${res}:${pad(seconds)}.${ms} (${hours !== 0 ? 'h:m' : ''}m:ss.mmm)`;

lib/internal/worker/js_transferable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function setup() {
3535
// from .postMessage() calls. The format of `deserializeInfo` is generally
3636
// 'module:Constructor', e.g. 'internal/fs/promises:FileHandle'.
3737
setDeserializerCreateObjectFunction((deserializeInfo) => {
38-
const { 0: module, 1: ctor } = StringPrototypeSplit(deserializeInfo, ':');
38+
const { 0: module, 1: ctor } = StringPrototypeSplit(deserializeInfo, ':', 2);
3939
const Ctor = require(module)[ctor];
4040
if (typeof Ctor !== 'function' ||
4141
typeof Ctor.prototype[messaging_deserialize_symbol] !== 'function') {

lib/tls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ function check(hostParts, pattern, wildcards) {
255255

256256
const hostSubdomain = hostParts[0];
257257
const patternSubdomain = patternParts[0];
258-
const patternSubdomainParts = patternSubdomain.split('*');
258+
const patternSubdomainParts = patternSubdomain.split('*', 3);
259259

260260
// Short-circuit when the subdomain does not contain a wildcard.
261261
// RFC 6125 does not allow wildcard substitution for components

0 commit comments

Comments
 (0)