{"record":{"id":"a540bb631c618d13","repo":"heygen-com/hyperframes","slug":"freeze-failed-bytes-length-bytes-exceeds-max","errorCode":null,"errorMessage":"freeze failed: ${bytes.length} bytes exceeds ${MAX_FREEZE_BYTES} cap","messagePattern":"freeze failed: (.+?) bytes exceeds (.+?) cap","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/figma/freeze.ts","lineNumber":19,"sourceCode":"/**\n * \"Freeze\" = write asset bytes to local disk permanently so renders never\n * re-fetch from figma (design spec §5) — not Object.freeze.\n */\n\nimport { copyFileSync, mkdirSync, rmSync, statSync, writeFileSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\n\n// ponytail: bound the write so a hostile/runaway source can't fill the disk.\nexport const MAX_FREEZE_BYTES = 256 * 1024 * 1024;\n\nexport function exceedsFreezeCap(byteLength: number): boolean {\n  return byteLength > MAX_FREEZE_BYTES;\n}\n\nexport function freezeBytes(bytes: Uint8Array, destPath: string): number {\n  if (bytes.length === 0) throw new Error(\"freeze failed: empty bytes\");\n  if (exceedsFreezeCap(bytes.length))\n    throw new Error(`freeze failed: ${bytes.length} bytes exceeds ${MAX_FREEZE_BYTES} cap`);\n  mkdirSync(dirname(destPath), { recursive: true });\n  // Exclusive create; on EEXIST remove and retry — never write through an\n  // existing file or planted symlink (CodeQL js/insecure-temporary-file).\n  try {\n    writeFileSync(destPath, bytes, { flag: \"wx\" });\n  } catch (err) {\n    if ((err as NodeJS.ErrnoException).code !== \"EEXIST\") throw err;\n    rmSync(destPath);\n    writeFileSync(destPath, bytes, { flag: \"wx\" });\n  }\n  return bytes.length;\n}\n\n/**\n * Only figma-owned hosts may be frozen from a URL — render/CDN responses\n * come from figma.com subdomains or figma's S3 buckets. Blocks SSRF via a\n * crafted manifest/config URL (metadata endpoints, internal services).\n */","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/core/src/figma/freeze.ts#L1-L37","documentation":"Thrown by freezeBytes when the supplied byte length exceeds MAX_FREEZE_BYTES (256 MiB). This is the on-write half of the size cap: it checks the actual buffer length rather than a declared header, so it catches a runaway/huge payload even when content-length was absent or lied about. The cap is a deliberate guard against a hostile or runaway source filling the disk — without it a crafted manifest URL could exhaust storage during a render.","triggerScenarios":"Passing a large downloaded image/video to freezeBytes; an asset whose real size is > 256 MiB regardless of what its content-length header claimed; calling freezeBytes directly with a multi-hundred-MB Uint8Array.","commonSituations":"Importing a very high-resolution figma image at 4x scale; a figma file with an embedded video asset that exceeds the cap; bundling a project whose LUT or texture is unexpectedly huge.","solutions":["Reduce the render scale (opts.scale on renderNode) to shrink the asset.","Export the asset at a lower resolution from figma before importing.","If you genuinely need larger assets and accept the disk risk, raise MAX_FREEZE_BYTES in a fork — but prefer shrinking the source.","Check whether the wrong node was targeted (a parent frame export instead of a single image)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { exceedsFreezeCap } from '.../figma/freeze';\nexport function assertUnderCap(byteLength: number): void {\n  if (exceedsFreezeCap(byteLength)) {\n    throw new Error(`asset is ${byteLength} bytes — shrink it below the 256 MiB cap`);\n  }\n}\n// usage\nassertUnderCap(buf.length);\nawait freezeBytes(buf, dest);","typeGuard":null,"tryCatchPattern":"try {\n  await freezeBytes(buf, dest);\n} catch (err) {\n  if (err instanceof Error && /exceeds .* cap/.test(err.message)) {\n    // re-render at lower scale, or skip\n  } else throw err;\n}","preventionTips":["Render figma nodes at the lowest scale that still meets quality needs.","Pre-check asset size before freezing so the error message is actionable.","Audit large figma files for oversized embedded media before bulk import."],"tags":["figma","freeze","size-limit","validation","assets"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}