Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 34f4934

Browse filesBrowse files
joyeecheungMylesBorins
authored andcommitted
fs: fix stack overflow in fs.readdirSync
Previously, fs.readdirSync calls the function returned by env->push_values_to_array_function() in batch and check the returned Maybe right away in C++, which can lead to assertions if the call stack already reaches the maximum size. This patch fixes that by returning early the call fails so the stack overflow error will be properly thrown into JS land. PR-URL: #18647 Fixes: #18645 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a7419d0 commit 34f4934
Copy full SHA for 34f4934

File tree

Expand file treeCollapse file tree

2 files changed

+27
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-3
lines changed
Open diff view settings
Collapse file

‎src/node_file.cc‎

Copy file name to clipboardExpand all lines: src/node_file.cc
+9-3Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,14 +909,20 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
909909
name_v[name_idx++] = filename.ToLocalChecked();
910910

911911
if (name_idx >= arraysize(name_v)) {
912-
fn->Call(env->context(), names, name_idx, name_v)
913-
.ToLocalChecked();
912+
MaybeLocal<Value> ret = fn->Call(env->context(), names, name_idx,
913+
name_v);
914+
if (ret.IsEmpty()) {
915+
return;
916+
}
914917
name_idx = 0;
915918
}
916919
}
917920

918921
if (name_idx > 0) {
919-
fn->Call(env->context(), names, name_idx, name_v).ToLocalChecked();
922+
MaybeLocal<Value> ret = fn->Call(env->context(), names, name_idx, name_v);
923+
if (ret.IsEmpty()) {
924+
return;
925+
}
920926
}
921927

922928
args.GetReturnValue().Set(names);
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const fs = require('fs');
6+
7+
function recurse() {
8+
fs.readdirSync('.');
9+
recurse();
10+
}
11+
12+
common.expectsError(
13+
() => recurse(),
14+
{
15+
type: RangeError,
16+
message: 'Maximum call stack size exceeded'
17+
}
18+
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.