can1357/oh-my-pi · error · ArchiveError
Invalid CPIO archive: newc checksum field must be zero
Error message
Invalid CPIO archive: newc checksum field must be zero
What it means
For the 'new ASCII' magic '070701' (plain newc), the 13th header field is the checksum and must be 0; only the '070702' (CRC) variant carries a meaningful checksum. The library throws ArchiveError when a newc header declares magic 070701 but a non-zero checksum, an internally inconsistent header. It protects users from silently skipping verification or trusting contradictory metadata.
Source
Thrown at packages/utils/src/ar/cpio.ts:152
devMajor: 0,
devMinor: read16(bytes, offset + 2),
inode: read16(bytes, offset + 4),
mode: read16(bytes, offset + 6),
nlink: read16(bytes, offset + 12),
mtime: read32Words(16),
nameSize: read16(bytes, offset + 20),
fileSize: read32Words(22),
};
}
requireRange(bytes, offset, offset + 6, "magic");
const magic = String.fromCharCode(...bytes.subarray(offset, offset + 6));
if (magic === "070701" || magic === "070702") {
requireRange(bytes, offset, offset + NEWC_HEADER_SIZE, "new ASCII header");
const field = (index: number, name: string): number => parseDigits(bytes, offset + 6 + index * 8, 8, 16, name);
const checksum = field(12, "checksum");
if (magic === "070701" && checksum !== 0) {
throw new ArchiveError("Invalid CPIO archive: newc checksum field must be zero");
}
return {
headerSize: NEWC_HEADER_SIZE,
alignment: 4,
inode: field(0, "inode"),
mode: field(1, "mode"),
nlink: field(4, "link count"),
mtime: field(5, "modification time"),
fileSize: field(6, "file size"),
devMajor: field(7, "device major"),
devMinor: field(8, "device minor"),
nameSize: field(11, "name size"),
checksum: magic === "070702" ? checksum : undefined,
};
}
if (magic === "070707") {
requireRange(bytes, offset, offset + ODC_HEADER_SIZE, "portable ASCII header");
const field6 = (fieldOffset: number, name: string): number =>View on GitHub (pinned to 9690622007)
Solutions
- Regenerate the archive in the intended format: use cpio -H newc (checksum 0) or -H crc (magic 070702) as appropriate
- If CRC verification is wanted, rewrite the archive with magic '070702' so the checksum is honored instead of required to be zero
- Zero out inconsistent checksum fields only if you control the writer and know verification is not desired
- Compare output of `cpio -itv` against your writer to confirm the header layout
Example fix
// before: writer stamps newc magic but fills checksum
header.write('070701', 0, 'ascii');
header.write(checksum.toString(16).padStart(8, '0'), 6 + 12 * 8, 'ascii');
// after: keep checksum zero for newc, or use crc magic
header.write('070701', 0, 'ascii');
header.write('00000000', 6 + 12 * 8, 'ascii'); Defensive patterns
Strategy: validation
Validate before calling
const head = Buffer.from(new Uint8Array(await source.slice(0, 110)));
if (head.toString('ascii', 0, 6) === '070701') {
const checksum = parseInt(head.toString('ascii', 6 + 12 * 8, 6 + 13 * 8), 16);
if (checksum !== 0) throw new Error('newc header carries non-zero checksum; expected 070702 (CRC) format');
} Try / catch
try {
const entries = await readCpio(source, options);
} catch (err) {
if (err instanceof ArchiveError && err.message.includes('checksum field must be zero')) {
// rewrite archive with -H crc or regenerate as plain newc
} else throw err;
} Prevention
- Write newc archives with cpio -H newc (zero checksum) or -H crc (magic 070702), never mixed
- Do not manually patch header bytes in generated archives
- Validate writer output against GNU cpio before distribution
When it happens
Trigger: Calling readCpio/readRpmArchive/entries on an archive whose headers use magic '070701' with a populated checksum field — e.g. an archive written as CRC format but with the magic bytes of plain newc, or bytes patched/corrupted in the checksum field.
Common situations: Custom writers that always emit the checksum (copied from CRC-mode code) while stamping the 070701 magic; manual byte patching; tool-version mismatches where the CRC variant was intended (the file should then use magic 070702).
Related errors
- CPIO member '${memberPath}' has an invalid CRC checksum
- Invalid ARJ basic header CRC32
- Invalid ARJ extended header CRC32
- Invalid CAB archive: CFDATA block ${block} checksum mismatch
- Invalid XZ stream: footer CRC32 mismatch
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/e21593e66207f230.
Report an issue: GitHub.