{"record":{"id":"dbb61f27a4f8bce8","repo":"can1357/oh-my-pi","slug":"invalid-rpm-package-truncated-what-header","errorCode":null,"errorMessage":"Invalid RPM package: truncated ${what} header","messagePattern":"Invalid RPM package: truncated (.+?) header","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/rpm.ts","lineNumber":74,"sourceCode":"\tif (bytes.byteLength !== RPM_HEADER_INTRO_SIZE || readUInt32BE(bytes, 0) !== RPM_HEADER_MAGIC) {\n\t\tthrow new ArchiveError(`Invalid RPM package: corrupt ${what} header magic`);\n\t}\n\tfor (let offset = 4; offset < 8; offset++) {\n\t\tif (bytes[offset] !== 0) throw new ArchiveError(`Invalid RPM package: corrupt ${what} header reserved bytes`);\n\t}\n\tconst indexCount = readUInt32BE(bytes, 8);\n\tconst dataSize = readUInt32BE(bytes, 12);\n\tassertEntryCount(indexCount, options.limits);\n\tconst indexSize = indexCount * RPM_INDEX_ENTRY_SIZE;\n\tconst bodySize = indexSize + dataSize;\n\tif (!Number.isSafeInteger(bodySize)) throw new ArchiveError(`Invalid RPM package: ${what} header is too large`);\n\tassertIndexSize(RPM_HEADER_INTRO_SIZE + bodySize, options.limits, `RPM ${what} header`);\n\treturn { indexCount, dataSize, bodySize, totalSize: RPM_HEADER_INTRO_SIZE + bodySize };\n}\n\nfunction validateHeaderBody(body: Uint8Array, intro: HeaderIntro, what: string): void {\n\tconst indexSize = intro.indexCount * RPM_INDEX_ENTRY_SIZE;\n\tif (body.byteLength !== intro.bodySize) throw new ArchiveError(`Invalid RPM package: truncated ${what} header`);\n\tfor (let index = 0; index < intro.indexCount; index++) {\n\t\tconst recordOffset = index * RPM_INDEX_ENTRY_SIZE;\n\t\tconst tag = readUInt32BE(body, recordOffset);\n\t\tconst type = readUInt32BE(body, recordOffset + 4);\n\t\tconst offset = readUInt32BE(body, recordOffset + 8);\n\t\tconst count = readUInt32BE(body, recordOffset + 12);\n\t\tif (offset > intro.dataSize) throw new ArchiveError(`Invalid RPM package: tag ${tag} points outside header data`);\n\t\tconst remaining = intro.dataSize - offset;\n\t\tlet elementSize = 0;\n\t\tif (type === 1 || type === 2 || type === 7) elementSize = 1;\n\t\telse if (type === 3) elementSize = 2;\n\t\telse if (type === 4) elementSize = 4;\n\t\telse if (type === 5) elementSize = 8;\n\t\telse if (type === 0) {\n\t\t\tif (count !== 0) throw new ArchiveError(`Invalid RPM package: null tag ${tag} has values`);\n\t\t\tcontinue;\n\t\t} else if (type === RPM_TYPE_STRING || type === 8 || type === 9) {\n\t\t\tconst stringCount = type === RPM_TYPE_STRING ? 1 : count;","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/rpm.ts#L56-L92","documentation":"ArchiveError thrown by validateHeaderBody() when the header body byte length does not equal intro.bodySize computed from the intro — the header was declared with indexCount and dataSize but fewer (or more) bytes were actually read. Guards against truncated headers before index entries are interpreted.","triggerScenarios":"Signature or main header read where the body read came up short relative to the intro's declared bodySize — truncated file, or the source ends mid-header.","commonSituations":"Partially downloaded .rpm files, source streams cut off mid-header, corrupt mirrors.","solutions":["Re-download the package and verify size","Check disk/network integrity for the source file","Validate the file end-to-end (e.g. rpm -K) outside the library to confirm corruption"],"exampleFix":"// before\nconst blob = await response.blob();\nawait readRpmArchive(await blob.arrayBuffer());\n// after\nconst buf = new Uint8Array(await response.arrayBuffer());\nif (buf.byteLength !== expectedSize) throw new Error(`short download: ${buf.byteLength}/${expectedSize}`);\nawait readRpmArchive(buf);","handlingStrategy":"validation","validationCode":"const expected = await fetchExpectedSizeFromRepoMetadata(url);\nconst actual = Bun.file(path).size;\nif (actual !== expected) throw new Error(`incomplete download (${actual}/${expected})`);","typeGuard":"null","tryCatchPattern":"try {\n  const rpm = await readRpmArchive(buf);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes('truncated')) {\n    // prompt re-download\n  } else throw err;\n}","preventionTips":["Always compare downloaded size with repository metadata","Use resumable/checksummed downloads for large RPMs","Parse only after the file is fully written to disk"],"tags":["rpm","archive","truncated-file"],"backgroundTag":"archive-truncated","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}