can1357/oh-my-pi · error · ArchiveError
Invalid RPM package: string tag ${tag} has an invalid count
Error message
Invalid RPM package: string tag ${tag} has an invalid count What it means
RPM header entries of type RPM_TYPE_STRING (6) represent exactly one string, and the spec requires their count field to be 1. This parser enforces that invariant when validating the header body (signature or main header) via validateHeaderBody. If a STRING-tagged index entry declares count != 1, the package header is malformed or corrupted, so parsing aborts rather than reading a bogus value.
Source
Thrown at packages/utils/src/ar/rpm.ts:94
const recordOffset = index * RPM_INDEX_ENTRY_SIZE;
const tag = readUInt32BE(body, recordOffset);
const type = readUInt32BE(body, recordOffset + 4);
const offset = readUInt32BE(body, recordOffset + 8);
const count = readUInt32BE(body, recordOffset + 12);
if (offset > intro.dataSize) throw new ArchiveError(`Invalid RPM package: tag ${tag} points outside header data`);
const remaining = intro.dataSize - offset;
let elementSize = 0;
if (type === 1 || type === 2 || type === 7) elementSize = 1;
else if (type === 3) elementSize = 2;
else if (type === 4) elementSize = 4;
else if (type === 5) elementSize = 8;
else if (type === 0) {
if (count !== 0) throw new ArchiveError(`Invalid RPM package: null tag ${tag} has values`);
continue;
} else if (type === RPM_TYPE_STRING || type === 8 || type === 9) {
const stringCount = type === RPM_TYPE_STRING ? 1 : count;
if (type === RPM_TYPE_STRING && count !== 1) {
throw new ArchiveError(`Invalid RPM package: string tag ${tag} has an invalid count`);
}
if (stringCount > remaining) {
throw new ArchiveError(`Invalid RPM package: string tag ${tag} exceeds header data`);
}
let cursor = indexSize + offset;
const limit = indexSize + intro.dataSize;
for (let stringIndex = 0; stringIndex < stringCount; stringIndex++) {
while (cursor < limit && body[cursor] !== 0) cursor++;
if (cursor === limit) {
throw new ArchiveError(`Invalid RPM package: string tag ${tag} is not NUL-terminated`);
}
cursor++;
}
continue;
} else {
throw new ArchiveError(`Invalid RPM package: tag ${tag} uses unknown data type ${type}`);
}
if (offset % elementSize !== 0) throw new ArchiveError(`Invalid RPM package: tag ${tag} data is misaligned`);View on GitHub (pinned to 9690622007)
Solutions
- Re-download or rebuild the .rpm package; the file bytes are corrupt or non-conformant.
- Verify the file with an independent tool (e.g. `rpm -qp <file>`) to confirm whether the header is genuinely malformed.
- If the package is produced by your own tooling, fix it to emit count=1 for STRING (type 6) tags.
- Catch ArchiveError around readRpm and treat the file as an unsupported/invalid archive instead of crashing.
Example fix
// before: calling readRpm on a suspect file directly
const entries = await readRpm(source, options);
// after: validate and handle gracefully
import { sniffRpm } from "@oh-my-pi/pi-utils/ar/rpm";
if (!sniffRpm(leadBytes)) throw new Error("not an RPM");
try {
const entries = await readRpm(source, options);
} catch (err) {
if (err instanceof ArchiveError) return rejectPackage(err.message);
throw err;
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!sniffRpm(leadBytes)) throw new Error("not an RPM file"); // otherwise no cheap pre-check: the count field lives inside the binary header Try / catch
try {
const entries = await readRpm(source, options);
} catch (err) {
if (err instanceof ArchiveError && err.message.includes("invalid count")) {
return { ok: false, reason: "corrupt RPM header" };
}
throw err;
} Prevention
- Download packages over verified channels and check checksums/signatures before parsing.
- Pre-screen files with sniffRpm before invoking readRpm.
- Do not hand-edit .rpm files; rebuild with rpmbuild instead.
When it happens
Trigger: readRpm() (or readRpmArchive/parseMainHeader) encounters an index entry with type === 6 whose count field is 0 or >= 2. This can come from a hand-edited or corrupt .rpm, a truncated/garbled download, or a file that is not really an RPM but happens to pass the lead magic sniff.
Common situations: Corrupted or partially downloaded .rpm files; fuzzed/malicious packages; hand-crafted headers from custom build tooling that writes wrong count fields; misidentified archives fed to the RPM reader.
Related errors
- Invalid RPM package: corrupt ${what} header magic
- Invalid RPM package: corrupt ${what} header reserved bytes
- Invalid RPM package: tag ${tag} points outside header data
- Invalid RPM package: null tag ${tag} has values
- Invalid RPM package: string tag ${tag} exceeds header data
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/1cd47e3ed04a4395.
Report an issue: GitHub.