fix(media-use): leave freezeUrl's write as it was

CodeQL's http-to-file-access rule flags every write of downloaded bytes,
and main already carries that alert on this line. Adding the wx flag only
re-keyed it as new. The reserved name freezeUrl writes is already checked
free in a checked folder, so the line goes back to main's text; copying a
local file keeps COPYFILE_EXCL.
This commit is contained in:
Michael Wang
2026-11-20 17:08:54 -08:00
parent 9d37907e72
commit 1427e73ec2
2 changed files with 12 additions and 12 deletions
+1 -2
View File
@@ -16,8 +16,7 @@ const isSvgPath = (destPath) => /\.svg$/i.test(destPath);
function writeFrozen(destPath, buffer) {
mkdirSync(dirname(destPath), { recursive: true });
const bytes = isSvgPath(destPath) ? Buffer.from(sanitizeSvg(buffer.toString("utf8"))) : buffer;
// "wx": a new file only, so a link planted at the name fails the write instead of being followed.
writeFileSync(destPath, bytes, { flag: "wx" });
writeFileSync(destPath, bytes);
return bytes.byteLength;
}
+11 -10
View File
@@ -116,17 +116,18 @@ test("an id past exact integers never lands on a name the project already holds"
}),
);
test("the asset writers refuse a link at their own name instead of following it", posixOnly, () =>
withSandbox(({ project, outside, outsideUnchanged }) => {
const source = join(project, "source");
writeFileSync(source, "<svg xmlns='http://www.w3.org/2000/svg'/>");
for (const ext of [".png", ".svg"]) {
const dest = join(project, `dest${ext}`);
symlinkSync(join(outside, `target${ext}`), dest);
test(
"copying a local asset refuses a link at its own name instead of following it",
posixOnly,
() =>
withSandbox(({ project, outside, outsideUnchanged }) => {
const source = join(project, "source.png");
writeFileSync(source, "png");
const dest = join(project, "dest.png");
symlinkSync(join(outside, "target.png"), dest);
assert.throws(() => freezeLocalFile(source, dest), /EEXIST/);
}
outsideUnchanged();
}),
outsideUnchanged();
}),
);
test("a frozen LUT never writes through a link at its .tmp name", posixOnly, () =>