Skip to content

Commit b92c0cb

Browse files
lundibundicodebytere
authored andcommitted
fs: fix realpath inode link caching
The `fs.realpath` / `fs.realpathSync` cache already seen symbolic links using the inode number which may be longer that max supported JS number (2**53) and will therefore be incorrectly handled by possibly entering infinite loop of calling stat on the same node. This PR changes those functions (where appropriate) to use bigint for inode numbers. Fixes: #33936 PR-URL: #33945 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 2e38f0d commit b92c0cb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/fs.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
const {
2828
Map,
2929
MathMax,
30+
Number,
3031
NumberIsSafeInteger,
3132
ObjectCreate,
3233
ObjectDefineProperties,
@@ -174,7 +175,10 @@ const isFd = isUint32;
174175
function isFileType(stats, fileType) {
175176
// Use stats array directly to avoid creating an fs.Stats instance just for
176177
// our internal use.
177-
return (stats[1/* mode */] & S_IFMT) === fileType;
178+
let mode = stats[1];
179+
if (typeof mode === 'bigint')
180+
mode = Number(mode);
181+
return (mode & S_IFMT) === fileType;
178182
}
179183

180184
function access(path, mode, callback) {
@@ -1614,7 +1618,7 @@ function realpathSync(p, options) {
16141618

16151619
const baseLong = pathModule.toNamespacedPath(base);
16161620
const ctx = { path: base };
1617-
const stats = binding.lstat(baseLong, false, undefined, ctx);
1621+
const stats = binding.lstat(baseLong, true, undefined, ctx);
16181622
handleErrorFromBinding(ctx);
16191623

16201624
if (!isFileType(stats, S_IFLNK)) {
@@ -1747,7 +1751,7 @@ function realpath(p, options, callback) {
17471751
return process.nextTick(LOOP);
17481752
}
17491753

1750-
return fs.lstat(base, gotStat);
1754+
return fs.lstat(base, { bigint: true }, gotStat);
17511755
}
17521756

17531757
function gotStat(err, stats) {

0 commit comments

Comments
 (0)