The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Assist: skill zips capped by inflated bytes; read_source works over MCP with project_id
Claude3ae61ed7da6a
diff --git a/src/server/assist/context-tools.ts b/src/server/assist/context-tools.tsindex 93bddc56..1eaa8a3d 100644--- a/src/server/assist/context-tools.ts+++ b/src/server/assist/context-tools.ts@@ -5,7 +5,7 @@ import { getSkill, skillFile } from "../skills";import { canUseSkill, skillsFor } from "./context";import { defineTool } from "./define";import { addMemory, deleteMemory } from "./memory";-import { getProject, sourceText } from "./projects";+import { getProject, listProjects, sourceText } from "./projects";/** Tools for Skills, Memory and Projects (Supercomputer's "load skill", "use and update memory", "project assets"). */@@ -95,15 +95,30 @@ const remember = defineTool({const readSource = defineTool({name: "read_source",- description: "Read the full text of one of this project's sources (a page, a document, a note) by the id shown in the project's source list. Only works inside a project.",+ description:+ "Read the full text of one of this project's sources (a page, a document, a note) by the id shown in the project's source list. Only works inside a project. Over MCP (no chat), pass project_id too; leave out id to list the projects and their sources.",schema: z.object({- id: z.string().describe("The source id from the context, e.g. Ab3dE9xK1q."),+ id: z.string().optional().describe("The source id from the context, e.g. Ab3dE9xK1q."),+ project_id: z.string().optional().describe("Over MCP only: the project the source belongs to (a chat always reads its own project)."),}),- async run({ id }, ctx) {- const projectId = ctx.thread?.projectId;- if (!projectId || !getProject(projectId)) return { content: "This chat isn't in a project, so it has no sources.", isError: true };- const s = sourceText(projectId, id.replace(/^\[|\]$/g, ""));- if (!s) return { content: `No source ${id} in this project.`, isError: true };+ async run({ id, project_id }, ctx) {+ // A chat reads only its own project's sources; MCP names the project.+ const projectId = ctx.thread ? ctx.thread.projectId : project_id?.trim() || null;+ const project = projectId ? getProject(projectId) : null;+ const sourceId = id?.replace(/^\[|\]$/g, "").trim();+ if (!ctx.thread && (!project || !sourceId)) {+ if (projectId && !project) return { content: `No project ${projectId}. Call read_source without arguments to list them.`, isError: true };+ const list = project ? [project] : listProjects();+ return {+ content: JSON.stringify(+ list.map((p) => ({ project_id: p.id, name: p.name, sources: p.sources.map((x) => ({ id: x.id, kind: x.kind, title: x.title, ...(x.url && { url: x.url }), ...(x.chars && { chars: x.chars }), ...(x.status === "error" && { error: x.error }) })) })),+ ),+ };+ }+ if (!project) return { content: "This chat isn't in a project, so it has no sources.", isError: true };+ if (!sourceId) return { content: `Pass the id of a source: ${project.sources.map((x) => `${x.id} (${x.title})`).join(", ") || "this project has none"}.`, isError: true };+ const s = sourceText(project.id, sourceId);+ if (!s) return { content: `No source ${sourceId} in this project.`, isError: true };if (!s.text) return { content: JSON.stringify({ title: s.source.title, kind: s.source.kind, url: s.source.url, note: s.source.error ?? "This source has no text: pass its URL as an input instead." }) };return {content: `# ${s.source.title}${s.source.url ? `\n${s.source.url}` : ""}\n\n${s.text}`,diff --git a/src/server/assist/unzip.ts b/src/server/assist/unzip.tsindex 5d876342..d50d591f 100644--- a/src/server/assist/unzip.ts+++ b/src/server/assist/unzip.ts@@ -52,22 +52,29 @@ export function unzip(buf: Buffer, limits: { maxEntries?: number; maxFileBytes?:p += 46 + nameLen + extraLen + commentLen;if (name.endsWith("/")) continue;if (flags & 0x1) throw new ZipError("The archive is password-protected");- if (size > maxFile) throw new ZipError(`${name} is over ${Math.round(maxFile / 1_000_000)} MB`);- total += size;- if (total > maxTotal) throw new ZipError(`The archive unpacks to more than ${Math.round(maxTotal / 1_000_000)} MB`);+ const tooBig = () => new ZipError(`${name} is over ${Math.round(maxFile / 1_000_000)} MB`);+ const tooMuch = () => new ZipError(`The archive unpacks to more than ${Math.round(maxTotal / 1_000_000)} MB`);+ // The declared size rejects honest big archives early; the bytes actually inflated (below) are what count.+ if (size > maxFile) throw tooBig();+ if (total + size > maxTotal) throw tooMuch();if (local + 30 > buf.length || buf.readUInt32LE(local) !== LOCAL) throw new ZipError("The archive is damaged (local header)");const start = local + 30 + buf.readUInt16LE(local + 26) + buf.readUInt16LE(local + 28);const raw = buf.subarray(start, start + compressed);let data: Buffer;if (method === 0) data = Buffer.from(raw);else if (method === 8) {+ // Never inflate past what's left of either cap, whatever the headers claim.+ const room = Math.min(maxFile, maxTotal - total);try {- data = zlib.inflateRawSync(raw, { maxOutputLength: maxFile + 1 });- } catch {+ data = zlib.inflateRawSync(raw, { maxOutputLength: room + 1 });+ } catch (e) {+ if ((e as NodeJS.ErrnoException).code === "ERR_BUFFER_TOO_LARGE") throw room < maxFile ? tooMuch() : tooBig();throw new ZipError(`Couldn't unpack ${name}`);}} else throw new ZipError(`${name} uses a compression method Fuobe can't read (${method})`);- if (data.length > maxFile) throw new ZipError(`${name} is over ${Math.round(maxFile / 1_000_000)} MB`);+ if (data.length > maxFile) throw tooBig();+ total += data.length;+ if (total > maxTotal) throw tooMuch();out.push({ name, data });}return out;diff --git a/tests/assist-context.test.ts b/tests/assist-context.test.tsindex 1c194eda..819f0d77 100644--- a/tests/assist-context.test.ts+++ b/tests/assist-context.test.ts@@ -410,6 +410,23 @@ describe("MCP", () => {const ls = (await rpc("tools/call", { name: "load_skill", arguments: { name: "narration" } })) as { result: { content: { text: string }[] } };expect(ls.result.content[0].text).toMatch(/^# Narration \(\/narration\)/);});++ it("read_source over MCP lists the projects' sources, then reads one by project and id", async () => {+ const p = projects.createProject({ name: "MCP brief" });+ const note = await projects.addSource(p.id, { kind: "text", text: "Tone\nWarm and plain." });+ type Call = { result: { content: { text: string }[]; isError: boolean } };+ const listed = (await rpc("tools/call", { name: "read_source", arguments: {} })) as Call;+ expect(listed.result.isError).toBe(false);+ const all = JSON.parse(listed.result.content[0].text) as { project_id: string; sources: { id: string; title: string }[] }[];+ expect(all.find((x) => x.project_id === p.id)?.sources).toEqual([expect.objectContaining({ id: note.id, title: "Tone" })]);+ const read = (await rpc("tools/call", { name: "read_source", arguments: { project_id: p.id, id: note.id } })) as Call;+ expect(read.result.isError).toBe(false);+ expect(read.result.content[0].text).toMatch(/^# Tone[\s\S]*Warm and plain\.$/);+ expect(await rpc("tools/call", { name: "read_source", arguments: { project_id: "nope", id: note.id } })).toMatchObject({ result: { isError: true } });+ // In a chat outside a project there is still nothing to read, whatever project_id says.+ const chat = await tools.executeTool("read_source", { id: note.id, project_id: p.id }, { engine: "cloud", thread: { id: "t", projectId: null, skills: [], loadSkill: () => {} } });+ expect(chat).toMatchObject({ isError: true, content: expect.stringMatching(/isn't in a project/) });+ });});const video = "/api/files/uploads/2026-10-19/clip.mp4";diff --git a/tests/assist-skills.test.ts b/tests/assist-skills.test.tsindex 4c0bd161..949ec5cf 100644--- a/tests/assist-skills.test.ts+++ b/tests/assist-skills.test.ts@@ -2,6 +2,7 @@ import fs from "node:fs";import http from "node:http";import os from "node:os";import path from "node:path";+import zlib from "node:zlib";import { afterAll, beforeAll, describe, expect, it } from "vitest";import {contextUpdate,@@ -270,6 +271,44 @@ describe("skills on the server", () => {const big = zipStored([{ name: "SKILL.md", data: Buffer.alloc(3_000_000, 65) }]);expect(() => unzip(big)).toThrow(/over 2 MB/);});++ it("counts the bytes it inflates, not the sizes the headers claim", () => {+ // A crafted archive: 10 deflated entries of 1.5 MB each that all claim to be 10 bytes.+ const entries = Array.from({ length: 10 }, (_, k) => ({ name: Buffer.from(`f${k}.md`), data: zlib.deflateRawSync(Buffer.alloc(1_500_000, 65)) }));+ const parts: Buffer[] = [];+ const central: Buffer[] = [];+ let offset = 0;+ for (const e of entries) {+ const lh = Buffer.alloc(30);+ lh.writeUInt32LE(0x04034b50, 0);+ lh.writeUInt16LE(8, 8);+ lh.writeUInt32LE(e.data.length, 18);+ lh.writeUInt32LE(10, 22);+ lh.writeUInt16LE(e.name.length, 26);+ const ch = Buffer.alloc(46);+ ch.writeUInt32LE(0x02014b50, 0);+ ch.writeUInt16LE(8, 10);+ ch.writeUInt32LE(e.data.length, 20);+ ch.writeUInt32LE(10, 24);+ ch.writeUInt16LE(e.name.length, 28);+ ch.writeUInt32LE(offset, 42);+ parts.push(lh, e.name, e.data);+ central.push(ch, e.name);+ offset += 30 + e.name.length + e.data.length;+ }+ const dir = Buffer.concat(central);+ const end = Buffer.alloc(22);+ end.writeUInt32LE(0x06054b50, 0);+ end.writeUInt16LE(entries.length, 8);+ end.writeUInt16LE(entries.length, 10);+ end.writeUInt32LE(dir.length, 12);+ end.writeUInt32LE(offset, 16);+ const bomb = Buffer.concat([...parts, dir, end]);+ expect(bomb.length).toBeLessThan(100_000);+ expect(() => unzip(bomb)).toThrow(/unpacks to more than 8 MB/);+ expect(unzip(bomb, { maxTotalBytes: 20_000_000 })).toHaveLength(10);+ expect(() => unzip(bomb, { maxFileBytes: 1_000_000 })).toThrow(/f0\.md is over 1 MB/);+ });});describe("memory", () => {