Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(chat): reject malformed UTF-8 attachments
BlueSkyID666fe31fbecffee
diff --git a/src/main/features/chat_attachments.ts b/src/main/features/chat_attachments.tsindex 3719376b..5e79b831 100644--- a/src/main/features/chat_attachments.ts+++ b/src/main/features/chat_attachments.ts@@ -555,7 +555,7 @@ export async function uploadAttachment(}if (TEXT_EXTS.has(ext)) {const s = buf.toString('utf8');- if (Buffer.from(s, 'utf8').length !== buf.length) {+ if (!Buffer.from(s, 'utf8').equals(buf)) {return { ok: false, error: t('errors.not_utf8') };}}diff --git a/test/main/features/chat_attachments.test.ts b/test/main/features/chat_attachments.test.tsindex e5cbe52c..bee13d1b 100644--- a/test/main/features/chat_attachments.test.ts+++ b/test/main/features/chat_attachments.test.ts@@ -242,10 +242,31 @@ describe('chat_attachments › uploadAttachment', () => {expect(fs.existsSync(path.join(attDir(), 'huge.mp4'))).toBe(false);});- it('rejects non-UTF-8 content for text types', async () => {- const m = await loadMod();- const r = await m.uploadAttachment(UID, CID, 'bad.txt', Buffer.from([0xFF, 0xFE]));+ it.each([+ { label: 'invalid leading bytes', bytes: [0xFF, 0xFE] },+ { label: 'truncated four-byte character', bytes: [0xF0, 0x9F, 0x92] },+ { label: 'interrupted four-byte character', bytes: [0xF0, 0x90, 0x80, 0x41] },+ { label: 'truncated three-byte character', bytes: [0xE2, 0x82] },+ { label: 'surrogate encoding', bytes: [0xED, 0xA0, 0x80] },+ ])('rejects non-UTF-8 content for text types: $label', async ({ bytes }) => {+ const m = await loadMod();+ const buffer = Buffer.from(bytes);+ const r = await m.uploadAttachment(UID, CID, 'bad.txt', buffer);expect(r.ok).toBe(false);+ if (!r.ok) expect(r.error.toLowerCase()).toContain('utf-8');+ expect(m.listAttachments(UID, CID)).toEqual([]);+ const source = path.join(tmpDir, 'bad.txt');+ fs.writeFileSync(source, buffer);+ expect((await m.importAttachmentFromPath(UID, CID, source)).ok).toBe(false);+ expect(fs.readFileSync(source)).toEqual(buffer);+ expect(m.listAttachments(UID, CID)).toEqual([]);+ });++ it('preserves valid Unicode and an authored replacement character byte for byte', async () => {+ const m = await loadMod();+ const buffer = Buffer.from('\uFEFF中文 📝 \uFFFD');+ expect((await m.uploadAttachment(UID, CID, 'unicode.txt', buffer)).ok).toBe(true);+ expect(fs.readFileSync(path.join(attDir(), 'unicode.txt'))).toEqual(buffer);});it('rejects unknown extensions', async () => {