Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): bound complete encoded zip entry paths under 65535 bytes (R1-M2)

M378db1f79eaa
diff --git a/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.ts b/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.ts
index 8e8031fd1..517ffb289 100644
--- a/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/gfsFolderZip.test.ts
@@ -290,6 +290,41 @@ describe('createGfsFolderZip', () => {
expect(deps.download).not.toHaveBeenCalled()
})
+ it('skips entries whose complete path would overflow the 16-bit ZIP name field (R1-M2)', async () => {
+ // A 110-deep chain of 700-byte segment names crosses 65535 assembled
+ // bytes around depth ~93: the overlong child is skipped (visible notice,
+ // shortened path) and its subtree is pruned, so the walk stays bounded.
+ const longName = 'a'.repeat(700)
+ const depth = 110
+ const pages: Record<string, Array<{ items: GfsZipChildItem[]; nextCursor: null }>> = {}
+ const chainChild = (index: number) =>
+ index === depth - 1
+ ? folder({ resourceId: 'leaf', name: 'leaf.txt', kind: 'file' })
+ : folder({ resourceId: `f${index}`, name: longName, kind: 'directory' })
+ pages.root = [{ items: [chainChild(0)], nextCursor: null }]
+ for (let index = 0; index < depth - 1; index += 1) {
+ pages[`f${index}`] = [{ items: [chainChild(index + 1)], nextCursor: null }]
+ }
+ const deps = depsFor(pages)
+
+ const result = await createGfsFolderZip(
+ { resourceId: 'root', drive: 'main', name: 'Deep' },
+ { deps }
+ ).catch(error => error)
+
+ // The only file lived under the pruned subtree: nothing archivable, and
+ // the skip notice explains why with a path a human can read.
+ expect(result).toBeInstanceOf(GfsFolderZipEmptyError)
+ const skipped = (result as GfsFolderZipEmptyError).skipped
+ expect(skipped[0]?.reason).toBe('Path too long')
+ expect(skipped[0]?.path.length).toBeLessThan(120)
+ // The walk terminated at the overflow depth instead of chasing all 110
+ // levels: bounded listing work, no downloads.
+ expect(deps.listChildren.mock.calls.length).toBeLessThanOrEqual(110)
+ expect(deps.listChildren.mock.calls.length).toBeGreaterThanOrEqual(90)
+ expect(deps.download).not.toHaveBeenCalled()
+ })
+
it('refuses when the actual downloaded bytes exceed the ceiling', async () => {
const deps = depsFor(
{
diff --git a/desktop-app/ui/src/lib/gfsFolderZip.ts b/desktop-app/ui/src/lib/gfsFolderZip.ts
index ae1108b50..10ccc2765 100644
--- a/desktop-app/ui/src/lib/gfsFolderZip.ts
+++ b/desktop-app/ui/src/lib/gfsFolderZip.ts
@@ -139,6 +139,24 @@ export interface GfsZipFolderSource {
name: string
}
+/**
+ * Complete-entry path bound. ZIP name fields are 16-bit BYTE counts, so the
+ * fully assembled entry path (all segments joined) must stay strictly under
+ * 65535 encoded bytes. Segments are capped individually
+ * (`GFS_ZIP_MAX_SEGMENT_NAME_BYTES`); this bound closes the deep-nesting case
+ * where many legal segments stack past the field. An overlong entry is skipped
+ * with a visible notice, and an overlong DIRECTORY prunes its subtree — every
+ * descendant would overflow too (spec: ZIP budget model).
+ */
+export const GFS_ZIP_MAX_ENTRY_PATH_BYTES = 65535
+
+const zipPathEncoder = new TextEncoder()
+
+/** Human-noticeable stand-in for an over-long path (the real one is unusable). */
+function shortenForNotice(path: string): string {
+ return path.length > 80 ? `${path.slice(0, 48)}…${path.slice(-24)}` : path
+}
+
function toMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}
@@ -305,6 +323,10 @@ export async function createGfsFolderZip(
}
for (const child of page.items) {
const path = `${next.prefix}/${sanitizeZipSegment(child.name)}`
+ if (zipPathEncoder.encode(path).length >= GFS_ZIP_MAX_ENTRY_PATH_BYTES) {
+ skipped.push({ path: shortenForNotice(path), reason: 'Path too long' })
+ continue
+ }
if (child.readable === false) {
skipped.push({ path, reason: 'No access' })
continue