can1357/oh-my-pi · error · ArchiveError

CPIO member '${memberPath}' is truncated

Error message

CPIO member '${memberPath}' is truncated

What it means

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.

Source

Thrown at packages/utils/src/ar/cpio.ts:71

	readonly #bytes: Uint8Array;
	readonly #offset: number;
	readonly #size: number;
	readonly #checksum?: number;

	constructor(bytes: Uint8Array, offset: number, size: number, checksum?: number) {
		this.#bytes = bytes;
		this.#offset = offset;
		this.#size = size;
		this.#checksum = checksum;
	}

	async read(size: number, memberPath: string): Promise<Uint8Array> {
		if (size !== this.#size) {
			throw new ArchiveError(`CPIO member '${memberPath}' has an inconsistent declared size`);
		}
		const end = this.#offset + this.#size;
		if (end > this.#bytes.byteLength) {
			throw new ArchiveError(`CPIO member '${memberPath}' is truncated`);
		}
		const bytes = this.#bytes.subarray(this.#offset, end);
		if (this.#checksum !== undefined && checksumBytes(bytes) !== this.#checksum) {
			throw new ArchiveError(`CPIO member '${memberPath}' has an invalid CRC checksum`);
		}
		return bytes;
	}
}

function checksumBytes(bytes: Uint8Array): number {
	let checksum = 0;
	for (const byte of bytes) checksum = (checksum + byte) >>> 0;
	return checksum;
}

function align(value: number, alignment: number): number {
	const remainder = value % alignment;
	return remainder === 0 ? value : value + alignment - remainder;

View on GitHub (pinned to 9690622007)

Solutions

  1. Rebuild or re-download the cpio archive and retry
  2. Verify the file is complete: cpio -it < file should list all members without error
  3. If parsing manually, confirm you are starting at the correct offset in a larger container
  4. Check the generator (find | cpio -o) completed successfully

Example fix

// before: trusting a truncated initramfs
const entries = await readCpioEntriesFromBuffer(partialBuffer);
// after
const stat = await Bun.file(path).stat();
if (stat.size < expectedSize) throw new Error(`cpio truncated: ${stat.size}/${expectedSize} bytes`);
const entries = await readCpioEntriesFromBuffer(await Bun.file(path).bytes());
Defensive patterns

Strategy: validation

Validate before calling

// before parsing, confirm the buffer can plausibly hold the archive
function plausibleCpio(bytes: Uint8Array): boolean {
  const magic = Buffer.from(bytes.subarray(0, 6)).toString('ascii');
  return magic === '070701' || magic === '070702' || magic === '070707';
}
if (bytes.byteLength < 128 || !plausibleCpio(bytes)) throw new Error('cpio missing/truncated');

Try / catch

try {
  const entries = await readCpioEntriesFromBuffer(bytes);
} catch (err) {
  if (err instanceof ArchiveError && /is truncated/.test(err.message)) {
    // incomplete archive: re-acquire or report which member is cut off
    throw new Error(`cpio incomplete: ${err.message}`);
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/2ff019621c83bfdc. Report an issue: GitHub.