{"record":{"id":"d36928cafd04bbde","repo":"can1357/oh-my-pi","slug":"unpacked-asar-file-label-size-differs-from-it","errorCode":null,"errorMessage":"Unpacked ASAR file '${label}' size differs from its archive header (${stat.size} != ${this.#size} bytes)","messagePattern":"Unpacked ASAR file '(.+?)' size differs from its archive header \\((.+?) != (.+?) bytes\\)","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/asar.ts","lineNumber":163,"sourceCode":"\t}\n\n\tasync read(size: number, memberPath: string): Promise<Uint8Array> {\n\t\tconst label = formatArchivePathForError(memberPath);\n\t\tif (size !== this.#size) {\n\t\t\tthrow new ArchiveError(`ASAR member '${label}' has an inconsistent size`);\n\t\t}\n\t\tif (!this.#filePath) {\n\t\t\tthrow new ArchiveError(`Archive file '${label}' is unpacked and requires a filesystem-backed ASAR archive`);\n\t\t}\n\t\tconst file = Bun.file(this.#filePath);\n\t\tconst stat = await file.stat().catch(() => {\n\t\t\tthrow new ArchiveError(`Unpacked ASAR file '${label}' was not found`);\n\t\t});\n\t\tif (stat.isDirectory()) {\n\t\t\tthrow new ArchiveError(`Unpacked ASAR file '${label}' is a directory`);\n\t\t}\n\t\tif (stat.size !== this.#size) {\n\t\t\tthrow new ArchiveError(\n\t\t\t\t`Unpacked ASAR file '${label}' size differs from its archive header (${stat.size} != ${this.#size} bytes)`,\n\t\t\t);\n\t\t}\n\t\tlet bytes: Uint8Array;\n\t\ttry {\n\t\t\tbytes = await file.bytes();\n\t\t} catch (error) {\n\t\t\tthrow new ArchiveError(`Failed to read unpacked ASAR file '${label}': ${describeError(error)}`);\n\t\t}\n\t\tif (bytes.byteLength !== this.#size) {\n\t\t\tthrow new ArchiveError(`Unpacked ASAR file '${label}' changed while being read`);\n\t\t}\n\t\tverifyIntegrity(bytes, this.#integrity, memberPath);\n\t\treturn bytes;\n\t}\n}\n\nasync function readAsarIndex(source: ByteSource, options: FormatReadOptions): Promise<ArchiveIndexEntry[]> {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/asar.ts#L145-L181","documentation":"Thrown when the unpacked sidecar file exists and is a regular file, but its size on disk differs from the `size` recorded for that member in the ASAR header. The archive format relies on the header being authoritative, so the mismatch makes the payload untrustworthy.","triggerScenarios":"Reading an unpacked member whose sidecar file was modified, truncated, or replaced since the ASAR was packed (stat.size !== header-declared size).","commonSituations":"Files updated in place in .unpacked after packaging; partial downloads or interrupted copies; repacking the .asar without regenerating the .unpacked sidecars; editors/IDEs rewriting files on save.","solutions":["Restore the unpacked file to the exact content packed into the ASAR (re-extract from the original source)","Regenerate the ASAR header (repack) if the unpacked file was intentionally updated","Re-run your packaging tool so .asar and .unpacked are produced from the same build"],"exampleFix":"npx asar extract app.asar restore-dir/  # restore expected sidecar contents\n# then repack:\nnpx asar pack app/ app.asar --unpack-dir assets","handlingStrategy":"validation","validationCode":"const st = await Bun.file(sidecar).stat();\nif (st.size !== entry.size) throw new Error(`sidecar size ${st.size} != header ${entry.size} for ${entry.path}`);","typeGuard":null,"tryCatchPattern":"try { return await readMember(entry); } catch (e) { if (e instanceof ArchiveError && e.message.includes(\"size differs from its archive header\")) { /* re-extract sidecar or repack archive */ } throw e; }","preventionTips":["Never edit files inside .unpacked after packaging; rebuild instead","Repack both .asar and .unpacked in the same build step","Compare sizes of all sidecars against the header as a post-build check"],"tags":["asar","unpacked-files","size-mismatch","integrity","electron"],"backgroundTag":"archive-member-size-mismatch","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}