Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(webv2): bound .invk archives at both allocation boundaries
joshistoast64af0227892f
diff --git a/invokeai/frontend/webv2/src/workbench/projects/invk/archive.ts b/invokeai/frontend/webv2/src/workbench/projects/invk/archive.tsindex e83abcddac..927467e2b7 100644--- a/invokeai/frontend/webv2/src/workbench/projects/invk/archive.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/invk/archive.ts@@ -110,6 +110,10 @@ export const writeArchive = async (entries: InvkArchiveEntries): Promise<Blob> =});});+ if (packed.byteLength > INVK_MAX_ARCHIVE_BYTES) {+ throw new InvkFormatError('too-large', `Project archive would be ${packed.byteLength} bytes.`);+ }+return new Blob([packed as BlobPart], { type: INVK_MIME_TYPE });};diff --git a/invokeai/frontend/webv2/src/workbench/projects/invk/archivePackedLimit.test.ts b/invokeai/frontend/webv2/src/workbench/projects/invk/archivePackedLimit.test.tsnew file mode 100644index 0000000000..bc54ff7660--- /dev/null+++ b/invokeai/frontend/webv2/src/workbench/projects/invk/archivePackedLimit.test.ts@@ -0,0 +1,17 @@+import { expect, it, vi } from 'vitest';++import { INVK_MAX_ARCHIVE_BYTES, textEntry, writeArchive } from './archive';++vi.mock('fflate', () => ({+ zip: (_entries: unknown, callback: (error: Error | null, data: Uint8Array) => void) =>+ callback(null, { byteLength: INVK_MAX_ARCHIVE_BYTES + 1 } as Uint8Array),+}));++it('refuses oversized packed bytes before constructing a Blob', async () => {+ const blob = vi.spyOn(globalThis, 'Blob');++ await expect(writeArchive(new Map([['project.json', textEntry('{}')]]))).rejects.toMatchObject({+ reason: 'too-large',+ });+ expect(blob).not.toHaveBeenCalled();+});diff --git a/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.test.ts b/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.test.tsindex eef3ec51d6..967e66cfe8 100644--- a/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.test.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.test.ts@@ -1,6 +1,6 @@import { describe, expect, it, vi } from 'vitest';-import { binaryEntry, textEntry, writeArchive } from './archive';+import { binaryEntry, INVK_MAX_ARCHIVE_BYTES, textEntry, writeArchive } from './archive';import { InvkFormatError } from './format';import { readInvkArchive, restoreArchiveAssets } from './importProject';@@ -44,6 +44,14 @@ const validArchive = (overrides: Record<string, string | Uint8Array> = {}) =>});describe('readInvkArchive', () => {+ it('refuses an oversized file before allocating its bytes', async () => {+ const arrayBuffer = vi.fn(() => Promise.resolve(new ArrayBuffer(0)));+ const file = { arrayBuffer, size: INVK_MAX_ARCHIVE_BYTES + 1 } as unknown as File;++ await expect(readInvkArchive(file)).rejects.toMatchObject({ reason: 'too-large' });+ expect(arrayBuffer).not.toHaveBeenCalled();+ });+it('returns the manifest, document and bundled images', async () => {const contents = await readInvkArchive(await validArchive());diff --git a/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.ts b/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.tsindex 74cafcfd70..bddce813cd 100644--- a/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.ts+++ b/invokeai/frontend/webv2/src/workbench/projects/invk/importProject.ts@@ -4,7 +4,7 @@ import { collectLiveAssetRefs, selectCoverImageName } from '@workbench/projects/import type { UploadedImage, UploadedVideo } from './assetTransport';import type { InvkManifest } from './manifest';-import { readArchive, readEntryText } from './archive';+import { INVK_MAX_ARCHIVE_BYTES, readArchive, readEntryText } from './archive';import {findExistingImageNames,findExistingVideoNames,@@ -72,6 +72,10 @@ const parseDocumentEntry = (bytes: Uint8Array): Record<string, unknown> => {/** Unpack and validate an archive. Throws {@link InvkFormatError} and nothing else. */export const readInvkArchive = async (file: File): Promise<InvkArchiveContents> => {+ if (file.size > INVK_MAX_ARCHIVE_BYTES) {+ throw new InvkFormatError('too-large', `Project archive is ${file.size} bytes.`);+ }+const entries = await readArchive(new Uint8Array(await file.arrayBuffer()));const manifestEntry = entries.get(INVK_MANIFEST_ENTRY);