{"record":{"id":"1085745e0312ca01","repo":"can1357/oh-my-pi","slug":"asar-payload-is-too-large-to-encode-safely","errorCode":null,"errorMessage":"ASAR payload is too large to encode safely","messagePattern":"ASAR payload is too large to encode safely","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/asar.ts","lineNumber":440,"sourceCode":"\t\t\tfor (let index = 0; index < parts.length - 1; index++) {\n\t\t\t\tconst part = parts[index]!;\n\t\t\t\tconst existing = directory.files[part];\n\t\t\t\tif (existing && !(\"files\" in existing)) {\n\t\t\t\t\tthrow new ArchiveError(\n\t\t\t\t\t\t`ASAR member path '${memberPath}' crosses file '${parts.slice(0, index + 1).join(\"/\")}'`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (!existing) {\n\t\t\t\t\tdirectory.files[part] = { files: Object.create(null) as Record<string, AsarNode> };\n\t\t\t\t}\n\t\t\t\tdirectory = directory.files[part] as AsarDirectoryNode;\n\t\t\t}\n\t\t\tconst name = parts.at(-1)!;\n\t\t\tif (directory.files[name]) {\n\t\t\t\tthrow new ArchiveError(`Duplicate or conflicting ASAR member path '${memberPath}'`);\n\t\t\t}\n\t\t\tif (!Number.isSafeInteger(member[1].byteLength) || !Number.isSafeInteger(payloadSize + member[1].byteLength)) {\n\t\t\t\tthrow new ArchiveError(\"ASAR payload is too large to encode safely\");\n\t\t\t}\n\t\t\tdirectory.files[name] = { size: member[1].byteLength, offset: String(payloadSize) };\n\t\t\tpayloads.push(member[1]);\n\t\t\tpayloadSize += member[1].byteLength;\n\t\t}\n\n\t\tconst jsonBytes = ASAR_HEADER_ENCODER.encode(JSON.stringify(root));\n\t\tconst paddedJsonSize = alignAsarPayload(jsonBytes.byteLength);\n\t\tconst innerPayloadSize = 4 + paddedJsonSize;\n\t\tconst headerSize = 4 + innerPayloadSize;\n\t\tif (jsonBytes.byteLength > 0xffffffff || headerSize > 0xffffffff) {\n\t\t\tthrow new ArchiveError(\"ASAR header is too large to encode\");\n\t\t}\n\t\tconst dataOffset = ASAR_PICKLE_PREFIX_SIZE + headerSize;\n\t\tconst archiveSize = dataOffset + payloadSize;\n\t\tif (!Number.isSafeInteger(archiveSize)) {\n\t\t\tthrow new ArchiveError(\"ASAR archive is too large to encode safely\");\n\t\t}","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/asar.ts#L422-L458","documentation":"encodeAsar tracks the running total payload size and requires every member's byteLength, and the cumulative total, to stay within Number.MAX_SAFE_INTEGER (2^53-1). A member whose Uint8Array claims an unsafe size, or whose addition would push the total past that bound, makes offsets unreliable, so the library throws before writing anything.","triggerScenarios":"Calling encodeAsar/encodeArchive/bytes with a Uint8Array whose byteLength exceeds 2^53-1 (practically impossible from real buffers but possible from fake/hostile objects), or accumulating members whose combined size exceeds Number.MAX_SAFE_INTEGER.","commonSituations":"Archiving extremely large payloads or unbounded synthetic data in tests; a buggy Uint8Array-like object with a corrupt byteLength; streaming pipelines that lose track of accumulated archive size.","solutions":["Split the archive into multiple ASAR files so each stays well under the safe-integer limit.","Verify member contents are real Uint8Array/Blob-backed data with sane byteLength before encoding.","If archiving huge datasets, use chunked on-disk writing instead of one in-memory encode call.","Catch ArchiveError and report the total size; audit the member source for corrupted length metadata."],"exampleFix":"// before\nawait encodeAsar([...allHugeFiles]); // total payload > 2^53\n// after\nfor (const chunk of partition(allHugeFiles, maxChunkBytes)) {\n  await encodeAsar(chunk);\n}","handlingStrategy":"validation","validationCode":"function assertSafePayload(members) {\n  let total = 0;\n  for (const [, data] of members) {\n    if (!Number.isSafeInteger(data.byteLength)) throw new Error('member has unsafe byteLength');\n    total += data.byteLength;\n    if (!Number.isSafeInteger(total)) throw new Error('total ASAR payload exceeds safe integer range');\n  }\n}\nassertSafePayload(members);","typeGuard":"function isEncodableMember(m) {\n  return Array.isArray(m) && m.length === 2 &&\n    typeof m[0] === 'string' && m[1] instanceof Uint8Array &&\n    Number.isSafeInteger(m[1].byteLength);\n}","tryCatchPattern":"try {\n  const archive = await encodeAsar(members);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes('payload is too large')) {\n    throw new Error('Split the member set: total payload exceeds safe integer range');\n  }\n  throw err;\n}","preventionTips":["Track cumulative byteLength before encoding and split archives preemptively.","Validate members are real Uint8Array instances with sane byteLength.","Avoid reusing a single archive for unbounded/streamed datasets.","Log per-member sizes to spot corrupted length metadata early."],"tags":["asar","archive","size-limit","safe-integer"],"backgroundTag":"archive-size-limit-exceeded","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}