Skip to content

fix(cli): reject hard-linked aliases of program inputs as outputs - #1496

Open
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/output-input-hardlinks-20261011
Open

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/output-input-hardlinks-20261011

Conversation

@oxura

@oxura oxura commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #1495.

The CLI already refuses an output that is a program input by resolved path. A hard link has a different path but the same file identity, so JS emission truncated the original input and a subsequent run failed to parse it.

Compare existing output (dev, ino) against all loaded Bend and foreign input identities, using bigint stats to avoid rounding file IDs. Build the identity set lazily only when an independent existing output needs comparison; fresh outputs and already-known path/directory rejections do not stat every input. Keep the existing output error and ordinary independent output overwrite behavior.

A permanent installed-CLI assertion in the existing ping gate refuses a hard-linked sum.bend output, then runs the original input and expects 5n. The exact assertion fails against the unchanged source CLI and passes against the real rebuilt standalone CLI. It does not pin diagnostic wording or inspect implementation source. README documents file-identity protection; GUIDE/CHANGELOG and gate caps/policy are unchanged.

Actual local verification on Linux x64:

  • Current-main reproduction: -o alias.js exits 0 and overwrites the input; rerunning that input exits 1 with a parser error.
  • Source and standalone fixed CLIs refuse the original hard link and the original program still runs.
  • Both CLIs refuse hard-linked imported Bend and real host-effect JS inputs, same-path inputs, symlinks and directories. Both preserved dependency programs still run (42n and the real host cwd).
  • Fresh outputs and an independent existing output compile successfully; all six resulting Bun/Node consumer executions match the original program output.
  • Exact new ping assertion executed fail-before/pass-after against real CLI processes.
  • bun gates/repo.ts: 54/54.

The full installer/archive/hub ping flow was not run: its sibling site checkout is absent and the referenced GitHub site repository is not accessible here. Executing the isolated new assertion is not a claim that the full ping gate passed. This checks identity at validation time; it is not a claim of race-proof concurrent filesystem protection.

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.

CLI: -o through a hard-linked alias silently overwrites a program input

1 participant