Skip to content

AI-native design editor. Open-source Figma alternative.

fix(clipboard): catch invalid kiwi data in parseFigmaClipboard

Danila Poyarkov668309a5576f
diff --git a/packages/core/src/clipboard.ts b/packages/core/src/clipboard.ts
index ee0b32ba1..ed58ff821 100644
--- a/packages/core/src/clipboard.ts
+++ b/packages/core/src/clipboard.ts
@@ -42,23 +42,27 @@ export async function parseFigmaClipboard(
const meta: FigmaClipboardMeta = JSON.parse(atob(metaMatch[1]))
const binary = Uint8Array.fromBase64(bufMatch[1])
- const chunks = parseFigKiwiChunks(binary)
- if (!chunks) return null
-
- const schemaBytes = inflateSync(chunks[0])
- const schema = decodeBinarySchema(new ByteBuffer(schemaBytes))
- const compiled = compileSchema(schema)
- const dataRaw = await decompressFigKiwiDataAsync(chunks[1])
- const msg = compiled.decodeMessage(dataRaw) as {
- nodeChanges?: KiwiNodeChange[]
- blobs?: Array<{ bytes: Uint8Array | Record<string, number> }>
- }
+ try {
+ const chunks = parseFigKiwiChunks(binary)
+ if (!chunks) return null
+
+ const schemaBytes = inflateSync(chunks[0])
+ const schema = decodeBinarySchema(new ByteBuffer(schemaBytes))
+ const compiled = compileSchema(schema)
+ const dataRaw = await decompressFigKiwiDataAsync(chunks[1])
+ const msg = compiled.decodeMessage(dataRaw) as {
+ nodeChanges?: KiwiNodeChange[]
+ blobs?: Array<{ bytes: Uint8Array | Record<string, number> }>
+ }
- const blobs: Uint8Array[] = (msg.blobs ?? []).map((b) =>
- b.bytes instanceof Uint8Array ? b.bytes : new Uint8Array(Object.values(b.bytes))
- )
+ const blobs: Uint8Array[] = (msg.blobs ?? []).map((b) =>
+ b.bytes instanceof Uint8Array ? b.bytes : new Uint8Array(Object.values(b.bytes))
+ )
- return { nodes: msg.nodeChanges ?? [], meta, blobs }
+ return { nodes: msg.nodeChanges ?? [], meta, blobs }
+ } catch {
+ return null
+ }
}
const NON_VISUAL_TYPES = new Set([