Skip to content

Commit 11c6d7d

Browse files
committed
fix(files): deduplicate BINARY_DOC_TASKS and add size guard to VFS compiled-check
1 parent 5798b87 commit 11c6d7d

3 files changed

Lines changed: 16 additions & 15 deletions

File tree

apps/sim/app/api/workspaces/[id]/files/[fileId]/compiled-check/route.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,16 @@ import { toError } from '@sim/utils/errors'
33
import { type NextRequest, NextResponse } from 'next/server'
44
import { getSession } from '@/lib/auth'
55
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
6-
import { MAX_DOCUMENT_PREVIEW_CODE_BYTES } from '@/lib/execution/constants'
6+
import { BINARY_DOC_TASKS, MAX_DOCUMENT_PREVIEW_CODE_BYTES } from '@/lib/execution/constants'
77
import { runSandboxTask, SandboxUserCodeError } from '@/lib/execution/sandbox/run-task'
88
import { downloadWorkspaceFile, getWorkspaceFile } from '@/lib/uploads/contexts/workspace'
99
import { verifyWorkspaceMembership } from '@/app/api/workflows/utils'
10-
import type { SandboxTaskId } from '@/sandbox-tasks/registry'
1110

1211
export const dynamic = 'force-dynamic'
1312
export const runtime = 'nodejs'
1413

1514
const logger = createLogger('WorkspaceFileCompiledCheckAPI')
1615

17-
const BINARY_DOC_TASKS: Record<string, SandboxTaskId> = {
18-
docx: 'docx-generate',
19-
pptx: 'pptx-generate',
20-
pdf: 'pdf-generate',
21-
}
22-
2316
/**
2417
* GET /api/workspaces/[id]/files/[fileId]/compiled-check
2518
*

apps/sim/lib/copilot/vfs/workspace-vfs.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import {
5858
getAccessibleOAuthCredentials,
5959
} from '@/lib/credentials/environment'
6060
import { getPersonalAndWorkspaceEnv } from '@/lib/environment/utils'
61+
import { BINARY_DOC_TASKS, MAX_DOCUMENT_PREVIEW_CODE_BYTES } from '@/lib/execution/constants'
6162
import { runSandboxTask, SandboxUserCodeError } from '@/lib/execution/sandbox/run-task'
6263
import { getKnowledgeBases } from '@/lib/knowledge/service'
6364
import { listTables } from '@/lib/table/service'
@@ -80,19 +81,12 @@ import {
8081
} from '@/lib/workspaces/permissions/utils'
8182
import { getAllBlocks } from '@/blocks/registry'
8283
import { CONNECTOR_REGISTRY } from '@/connectors/registry'
83-
import type { SandboxTaskId } from '@/sandbox-tasks/registry'
8484
import { tools as toolRegistry } from '@/tools/registry'
8585
import { getLatestVersionTools, stripVersionSuffix } from '@/tools/utils'
8686
import { TRIGGER_REGISTRY } from '@/triggers/registry'
8787

8888
const logger = createLogger('WorkspaceVFS')
8989

90-
const BINARY_DOC_TASKS: Record<string, SandboxTaskId> = {
91-
docx: 'docx-generate',
92-
pptx: 'pptx-generate',
93-
pdf: 'pdf-generate',
94-
}
95-
9690
/** Static component files, computed once and shared across all VFS instances */
9791
let staticComponentFiles: Map<string, string> | null = null
9892

@@ -479,6 +473,12 @@ export class WorkspaceVFS {
479473
if (!taskId) return null
480474
const buffer = await downloadWorkspaceFile(record)
481475
const code = buffer.toString('utf-8')
476+
if (Buffer.byteLength(code, 'utf-8') > MAX_DOCUMENT_PREVIEW_CODE_BYTES) {
477+
return {
478+
content: JSON.stringify({ ok: false, error: 'File source exceeds maximum size' }),
479+
totalLines: 1,
480+
}
481+
}
482482
let result: { ok: boolean; error?: string; errorName?: string }
483483
try {
484484
await runSandboxTask(taskId, { code, workspaceId: this._workspaceId })

apps/sim/lib/execution/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DEFAULT_EXECUTION_TIMEOUT_MS } from '@/lib/core/execution-limits'
2+
import type { SandboxTaskId } from '@/sandbox-tasks/registry'
23

34
export { DEFAULT_EXECUTION_TIMEOUT_MS }
45

@@ -11,3 +12,10 @@ export { DEFAULT_EXECUTION_TIMEOUT_MS }
1112
* while reducing memory pressure and abuse potential from oversized payloads.
1213
*/
1314
export const MAX_DOCUMENT_PREVIEW_CODE_BYTES = 1 * 1024 * 1024
15+
16+
/** Maps file extension to the sandbox task that compiles/generates that document type. */
17+
export const BINARY_DOC_TASKS: Record<string, SandboxTaskId> = {
18+
docx: 'docx-generate',
19+
pptx: 'pptx-generate',
20+
pdf: 'pdf-generate',
21+
}

0 commit comments

Comments
 (0)