{"record":{"id":"2ff019621c83bfdc","repo":"can1357/oh-my-pi","slug":"cpio-member-memberpath-is-truncated","errorCode":null,"errorMessage":"CPIO member '${memberPath}' is truncated","messagePattern":"CPIO member '(.+?)' is truncated","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/cpio.ts","lineNumber":71,"sourceCode":"\treadonly #bytes: Uint8Array;\n\treadonly #offset: number;\n\treadonly #size: number;\n\treadonly #checksum?: number;\n\n\tconstructor(bytes: Uint8Array, offset: number, size: number, checksum?: number) {\n\t\tthis.#bytes = bytes;\n\t\tthis.#offset = offset;\n\t\tthis.#size = size;\n\t\tthis.#checksum = checksum;\n\t}\n\n\tasync read(size: number, memberPath: string): Promise<Uint8Array> {\n\t\tif (size !== this.#size) {\n\t\t\tthrow new ArchiveError(`CPIO member '${memberPath}' has an inconsistent declared size`);\n\t\t}\n\t\tconst end = this.#offset + this.#size;\n\t\tif (end > this.#bytes.byteLength) {\n\t\t\tthrow new ArchiveError(`CPIO member '${memberPath}' is truncated`);\n\t\t}\n\t\tconst bytes = this.#bytes.subarray(this.#offset, end);\n\t\tif (this.#checksum !== undefined && checksumBytes(bytes) !== this.#checksum) {\n\t\t\tthrow new ArchiveError(`CPIO member '${memberPath}' has an invalid CRC checksum`);\n\t\t}\n\t\treturn bytes;\n\t}\n}\n\nfunction checksumBytes(bytes: Uint8Array): number {\n\tlet checksum = 0;\n\tfor (const byte of bytes) checksum = (checksum + byte) >>> 0;\n\treturn checksum;\n}\n\nfunction align(value: number, alignment: number): number {\n\tconst remainder = value % alignment;\n\treturn remainder === 0 ? value : value + alignment - remainder;","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/cpio.ts#L53-L89","documentation":"Thrown when a CPIO member's data extends past the end of the input buffer — the header declares a size, but offset + size exceeds the bytes available. The archive is truncated or the header size is bogus.","triggerScenarios":"Calling readCpioEntriesFromBuffer / member.read on a truncated .cpio file, an initramfs image cut off mid-member, or a file with a corrupted filesize header field.","commonSituations":"Incomplete downloads of initramfs/cpio archives; initramfs built by a failing script; byte-offset errors when embedding a cpio inside another file; disk-space issues during creation.","solutions":["Rebuild or re-download the cpio archive and retry","Verify the file is complete: cpio -it < file should list all members without error","If parsing manually, confirm you are starting at the correct offset in a larger container","Check the generator (find | cpio -o) completed successfully"],"exampleFix":"// before: trusting a truncated initramfs\nconst entries = await readCpioEntriesFromBuffer(partialBuffer);\n// after\nconst stat = await Bun.file(path).stat();\nif (stat.size < expectedSize) throw new Error(`cpio truncated: ${stat.size}/${expectedSize} bytes`);\nconst entries = await readCpioEntriesFromBuffer(await Bun.file(path).bytes());","handlingStrategy":"validation","validationCode":"// before parsing, confirm the buffer can plausibly hold the archive\nfunction plausibleCpio(bytes: Uint8Array): boolean {\n  const magic = Buffer.from(bytes.subarray(0, 6)).toString('ascii');\n  return magic === '070701' || magic === '070702' || magic === '070707';\n}\nif (bytes.byteLength < 128 || !plausibleCpio(bytes)) throw new Error('cpio missing/truncated');","typeGuard":null,"tryCatchPattern":"try {\n  const entries = await readCpioEntriesFromBuffer(bytes);\n} catch (err) {\n  if (err instanceof ArchiveError && /is truncated/.test(err.message)) {\n    // incomplete archive: re-acquire or report which member is cut off\n    throw new Error(`cpio incomplete: ${err.message}`);\n  } else throw err;\n}","preventionTips":["Validate file size/checksum after download before extraction","Verify creation scripts (find | cpio -o) exit successfully","Check parser offsets when cpio is embedded in a larger container"],"tags":["cpio","archive","truncation","corruption"],"backgroundTag":"archive-truncated","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}