{"record":{"id":"0d5ce6bb9ced071b","repo":"can1357/oh-my-pi","slug":"asar-header-is-too-large-to-encode","errorCode":null,"errorMessage":"ASAR header is too large to encode","messagePattern":"ASAR header is too large to encode","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/asar.ts","lineNumber":452,"sourceCode":"\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}\n\t\tlet output: Uint8Array;\n\t\ttry {\n\t\t\toutput = new Uint8Array(archiveSize);\n\t\t} catch {\n\t\t\tthrow new ArchiveError(\"ASAR archive is too large to encode in memory\");\n\t\t}\n\t\twriteUInt32LE(output, 0, 4);\n\t\twriteUInt32LE(output, 4, headerSize);\n\t\twriteUInt32LE(output, 8, innerPayloadSize);\n\t\twriteUInt32LE(output, 12, jsonBytes.byteLength);\n\t\toutput.set(jsonBytes, ASAR_JSON_OFFSET);\n\t\tlet offset = dataOffset;","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/asar.ts#L434-L470","documentation":"The ASAR header is the Pickle-framed JSON directory tree, and its size fields are 32-bit. encodeAsar throws when the serialized JSON of the file tree exceeds 0xffffffff bytes or the aligned/framed header size overflows a uint32 — i.e. the tree has so many entries (or such long paths) that the header can't be represented in the ASAR format.","triggerScenarios":"Calling encodeAsar/encodeArchive/bytes with millions of members or extremely long path names so JSON.stringify(root) exceeds 4 GiB, or the padded/framed header size exceeds 0xffffffff.","commonSituations":"Archiving node_modules or a huge source tree with hundreds of thousands of files (header JSON can grow to hundreds of MB, though 4 GiB requires extreme cases); pathological synthetic member lists in tests with enormous generated path names.","solutions":["Reduce the number of members: exclude vendored/generated directories (node_modules, build outputs) before encoding.","Shorten member paths by restructuring the archive root or storing common prefixes out-of-band.","Split content across multiple ASAR archives.","Catch ArchiveError and report member count/total path length to guide the caller."],"exampleFix":"// before\nawait encodeAsar([...everyFileInProject]); // header JSON > 4 GiB\n// after\nconst filtered = members.filter(([p]) => !p.startsWith('node_modules/'));\nawait encodeAsar(filtered);","handlingStrategy":"validation","validationCode":"function estimateHeaderBytes(members) {\n  // rough upper bound: ~60 bytes of JSON overhead per entry plus path length\n  let est = 0;\n  for (const [p] of members) est += p.length + 120;\n  return est;\n}\nif (estimateHeaderBytes(members) > 0xf0000000) {\n  throw new Error('Too many members: ASAR header JSON would exceed 32-bit size fields');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const archive = await encodeAsar(members);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message === 'ASAR header is too large to encode') {\n    throw new Error('Reduce member count or split into multiple ASAR archives');\n  }\n  throw err;\n}","preventionTips":["Exclude node_modules/build outputs and other high-file-count directories from archives.","Keep member paths short; deep nesting inflates header JSON.","Split very large trees across multiple archives.","Monitor member count; hundreds of thousands of entries is a warning threshold."],"tags":["asar","archive","size-limit","header","uint32-overflow"],"backgroundTag":"archive-size-limit-exceeded","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}