Skip to content

Commit 957ba8e

Browse files
authored
fix crash in getFileInfo (#1143)
1 parent 009ff3a commit 957ba8e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/javascript/module.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createHash} from "node:crypto";
2-
import {readFileSync, statSync} from "node:fs";
2+
import {accessSync, constants, readFileSync, statSync} from "node:fs";
33
import {join} from "node:path/posix";
44
import type {Program} from "acorn";
55
import {resolvePath} from "../path.js";
@@ -141,10 +141,13 @@ export function getFileInfo(root: string, path: string): FileInfo | undefined {
141141
const key = join(root, path);
142142
let mtimeMs: number;
143143
try {
144-
({mtimeMs} = statSync(key));
144+
const stat = statSync(key);
145+
if (!stat.isFile()) return; // ignore non-files
146+
accessSync(key, constants.R_OK); // verify that file is readable
147+
({mtimeMs} = stat);
145148
} catch {
146149
fileInfoCache.delete(key); // delete stale entry
147-
return; // ignore missing file
150+
return; // ignore missing, non-readable file
148151
}
149152
let entry = fileInfoCache.get(key);
150153
if (!entry || entry.mtimeMs < mtimeMs) {

0 commit comments

Comments
 (0)