Skip to content

Quality: TOCTOU pattern when checking file existence before stat#2338

Open
tomaioo wants to merge 1 commit intoruntime-env:mainfrom
tomaioo:improve/quality/toctou-pattern-when-checking-file-existe
Open

Quality: TOCTOU pattern when checking file existence before stat#2338
tomaioo wants to merge 1 commit intoruntime-env:mainfrom
tomaioo:improve/quality/toctou-pattern-when-checking-file-existe

Conversation

@tomaioo
Copy link
Copy Markdown

@tomaioo tomaioo commented Apr 12, 2026

Summary

Quality: TOCTOU pattern when checking file existence before stat

Problem

Severity: Medium | File: packages/cli/src/resolve-output-file-names.ts:L9

existsSync(path) followed by lstatSync(path) introduces a time-of-check/time-of-use race. Files can disappear between calls, causing unexpected exceptions in concurrent or CI environments.

Solution

Use a single lstatSync inside a try/catch and filter based on the result, instead of separate existsSync and lstatSync calls.

Changes

  • packages/cli/src/resolve-output-file-names.ts (modified)

`existsSync(path)` followed by `lstatSync(path)` introduces a time-of-check/time-of-use race. Files can disappear between calls, causing unexpected exceptions in concurrent or CI environments.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant