Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: reject FIFO message files without blocking the filesystem pool
Afloat1d82d12b28c3
diff --git a/server/message-file.test.ts b/server/message-file.test.tsindex 2e63d75538..061e88d006 100644--- a/server/message-file.test.ts+++ b/server/message-file.test.ts@@ -1,4 +1,5 @@-import { mkdirSync, mkdtempSync, rmSync, symlinkSync, truncateSync, writeFileSync } from "node:fs";+import { execFileSync } from "node:child_process";+import { closeSync, constants, mkdirSync, mkdtempSync, openSync, rmSync, symlinkSync, truncateSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { pathToFileURL } from "node:url";@@ -34,6 +35,27 @@ beforeEach(() => {afterAll(() => rmSync(suite, { recursive: true, force: true }));describe("message-linked files", () => {+ it.skipIf(process.platform === "win32")("rejects a named pipe without waiting for a writer", async () => {+ const fifo = join(workspace, "waiting-pipe");+ execFileSync("mkfifo", [fifo]);+ let timer: ReturnType<typeof setTimeout> | undefined;+ const opened = openMessageFile(fifo, [workspace]).then(+ async (file) => { await file.handle.close(); return null; },+ (error: unknown) => error,+ );+ const result = await Promise.race([+ opened,+ new Promise<"blocked">((resolve) => { timer = setTimeout(() => resolve("blocked"), 1_000); }),+ ]);+ try {+ expect(result).toMatchObject({ status: 400, message: "the link does not point to a regular file" });+ } finally {+ clearTimeout(timer);+ if (result === "blocked") closeSync(openSync(fifo, constants.O_WRONLY | constants.O_NONBLOCK));+ await opened;+ }+ });+it("resolves a Markdown image from an opaque source offset", () => {const markdown = ["See this:",diff --git a/server/message-file.ts b/server/message-file.tsindex 369d21730c..e39774fa35 100644--- a/server/message-file.ts+++ b/server/message-file.ts@@ -410,7 +410,8 @@ export async function openMessageFile(let handle: FileHandle | undefined;try {const noFollow = typeof constants.O_NOFOLLOW === "number" ? constants.O_NOFOLLOW : 0;- handle = await open(canonicalBefore, constants.O_RDONLY | noFollow);+ const nonBlock = typeof constants.O_NONBLOCK === "number" ? constants.O_NONBLOCK : 0;+ handle = await open(canonicalBefore, constants.O_RDONLY | noFollow | nonBlock);const opened = await handle.stat();if (opened.isDirectory()) throw statusError(400, "the link points to a folder, not a file", "directory");if (!opened.isFile()) throw statusError(400, "the link does not point to a regular file");