leonida-lua: write_file writes through a hard link in the mod's folder to a file outside it #3212
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T19:34:42Z.
What happens. If a mod's folder contains a hard link to a file outside the folder,
write_filewrites through it and changes the outside file. This happens onmain(b41763227) and also with #3189 applied.Why.
manifest::inside()stops links and junctions by canonicalising the path and checking that the result starts with the mod's folder. A hard link has no target to resolve. It is just another name for the same file, so it canonicalises to its own path inside the folder and passes the check. After that,std::fs::writeopens it and truncates and writes the shared file.Repro (measured on Windows 11, NTFS, while verifying #3189).
outside.txtwith some content.mklink /H h.txt <path to outside.txt>. No admin and no Developer Mode needed. Hard links on NTFS need no special right.write_file("h.txt", "MOD").outside.txtnow containsMOD.Same result with the
inside()check from #3189. From reading the code,read_filegoes through the same check, so it would also read the outside file's contents. That part I did not run.How likely it is. Fairly low. A mod can't create a hard link from Lua. The only filesystem calls in
api.rsaremetadata,read,create_dir_allandwrite. Hard links also don't survive a zip, so a mod shipped as an archive can't carry one. Something else has to have placed the link in the folder already, like an installer, a script, or a mod manager that copies with links. Still, it's the same "write lands outside the folder" class thatinside()is there to stop, andinside()can't see it.Possible fixes (not tried).
GetFileInformationByHandle,nNumberOfLinks; on Unixst_nlink). Doing the same inread_filewould cover reads too.The first one also keeps a half-written file from being left behind if the process dies mid-write.
AI-assisted: yes (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T21:27:06Z.
PR #3226 is open and addresses this: it replaces the in-place write with a write that swaps in a new file, so a hard link in the mod folder is no longer written through. AI-assisted (Claude Code).