Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

fix(cli): size-check and read an edge-site file through one descriptor

KageBinary8435126b7a34
diff --git a/ix-cli/src/cli/edge-sites.ts b/ix-cli/src/cli/edge-sites.ts
index 9e7fe916..b7f2d1b8 100644
--- a/ix-cli/src/cli/edge-sites.ts
+++ b/ix-cli/src/cli/edge-sites.ts
@@ -235,9 +235,16 @@ export class SourceFiles {
try {
const abs = absoluteFromSourceUri(relPath, this.root);
if (isReadablePath(abs, this.root)) {
- const stat = fs.statSync(abs);
- if (stat.isFile() && stat.size <= MAX_FILE_BYTES) {
- lines = fs.readFileSync(abs, "utf-8").split("\n");
+ // One descriptor for the checks and the read, so the file measured is
+ // the file read (CodeQL js/file-system-race).
+ const fd = fs.openSync(abs, "r");
+ try {
+ const stat = fs.fstatSync(fd);
+ if (stat.isFile() && stat.size <= MAX_FILE_BYTES) {
+ lines = fs.readFileSync(fd, "utf-8").split("\n");
+ }
+ } finally {
+ fs.closeSync(fd);
}
}
} catch {