{"record":{"id":"e21593e66207f230","repo":"can1357/oh-my-pi","slug":"invalid-cpio-archive-newc-checksum-field-must-be","errorCode":null,"errorMessage":"Invalid CPIO archive: newc checksum field must be zero","messagePattern":"Invalid CPIO archive: newc checksum field must be zero","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/cpio.ts","lineNumber":152,"sourceCode":"\t\t\tdevMajor: 0,\n\t\t\tdevMinor: read16(bytes, offset + 2),\n\t\t\tinode: read16(bytes, offset + 4),\n\t\t\tmode: read16(bytes, offset + 6),\n\t\t\tnlink: read16(bytes, offset + 12),\n\t\t\tmtime: read32Words(16),\n\t\t\tnameSize: read16(bytes, offset + 20),\n\t\t\tfileSize: read32Words(22),\n\t\t};\n\t}\n\n\trequireRange(bytes, offset, offset + 6, \"magic\");\n\tconst magic = String.fromCharCode(...bytes.subarray(offset, offset + 6));\n\tif (magic === \"070701\" || magic === \"070702\") {\n\t\trequireRange(bytes, offset, offset + NEWC_HEADER_SIZE, \"new ASCII header\");\n\t\tconst field = (index: number, name: string): number => parseDigits(bytes, offset + 6 + index * 8, 8, 16, name);\n\t\tconst checksum = field(12, \"checksum\");\n\t\tif (magic === \"070701\" && checksum !== 0) {\n\t\t\tthrow new ArchiveError(\"Invalid CPIO archive: newc checksum field must be zero\");\n\t\t}\n\t\treturn {\n\t\t\theaderSize: NEWC_HEADER_SIZE,\n\t\t\talignment: 4,\n\t\t\tinode: field(0, \"inode\"),\n\t\t\tmode: field(1, \"mode\"),\n\t\t\tnlink: field(4, \"link count\"),\n\t\t\tmtime: field(5, \"modification time\"),\n\t\t\tfileSize: field(6, \"file size\"),\n\t\t\tdevMajor: field(7, \"device major\"),\n\t\t\tdevMinor: field(8, \"device minor\"),\n\t\t\tnameSize: field(11, \"name size\"),\n\t\t\tchecksum: magic === \"070702\" ? checksum : undefined,\n\t\t};\n\t}\n\tif (magic === \"070707\") {\n\t\trequireRange(bytes, offset, offset + ODC_HEADER_SIZE, \"portable ASCII header\");\n\t\tconst field6 = (fieldOffset: number, name: string): number =>","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/cpio.ts#L134-L170","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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"],"exampleFix":"// before: writer stamps newc magic but fills checksum\nheader.write('070701', 0, 'ascii');\nheader.write(checksum.toString(16).padStart(8, '0'), 6 + 12 * 8, 'ascii');\n// after: keep checksum zero for newc, or use crc magic\nheader.write('070701', 0, 'ascii');\nheader.write('00000000', 6 + 12 * 8, 'ascii');","handlingStrategy":"validation","validationCode":"const head = Buffer.from(new Uint8Array(await source.slice(0, 110)));\nif (head.toString('ascii', 0, 6) === '070701') {\n  const checksum = parseInt(head.toString('ascii', 6 + 12 * 8, 6 + 13 * 8), 16);\n  if (checksum !== 0) throw new Error('newc header carries non-zero checksum; expected 070702 (CRC) format');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const entries = await readCpio(source, options);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes('checksum field must be zero')) {\n    // rewrite archive with -H crc or regenerate as plain newc\n  } else throw err;\n}","preventionTips":["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"],"tags":["archive","cpio","newc","checksum"],"backgroundTag":"corrupt-archive-header","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}