{"record":{"id":"e601f579323f992c","repo":"can1357/oh-my-pi","slug":"invalid-rpm-package-tag-tag-string-is-not-nul","errorCode":null,"errorMessage":"Invalid RPM package: tag ${tag} string is not NUL-terminated","messagePattern":"Invalid RPM package: tag (.+?) string is not NUL-terminated","errorType":"validation","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/rpm.ts","lineNumber":134,"sourceCode":"}\n\nfunction readHeaderString(\n\tbody: Uint8Array,\n\tindexSize: number,\n\tdataSize: number,\n\toffset: number,\n\tcount: number,\n\ttype: number,\n\ttag: number,\n): string {\n\tif (type !== RPM_TYPE_STRING || count !== 1) {\n\t\tthrow new ArchiveError(`Invalid RPM package: tag ${tag} must contain one string`);\n\t}\n\tconst start = indexSize + offset;\n\tconst limit = indexSize + dataSize;\n\tlet end = start;\n\twhile (end < limit && body[end] !== 0) end++;\n\tif (end === limit) throw new ArchiveError(`Invalid RPM package: tag ${tag} string is not NUL-terminated`);\n\tif (end - start > 4096) throw new ArchiveError(`Invalid RPM package: tag ${tag} string is too large`);\n\ttry {\n\t\treturn UTF8_FATAL_DECODER.decode(body.subarray(start, end));\n\t} catch {\n\t\tthrow new ArchiveError(`Invalid RPM package: tag ${tag} is not valid UTF-8`);\n\t}\n}\n\nfunction parseMainHeader(body: Uint8Array, intro: HeaderIntro): RpmMetadata {\n\tvalidateHeaderBody(body, intro, \"main\");\n\tconst indexSize = intro.indexCount * RPM_INDEX_ENTRY_SIZE;\n\tif (body.byteLength !== intro.bodySize) throw new ArchiveError(\"Invalid RPM package: truncated main header\");\n\tconst metadata: RpmMetadata = {};\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);","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/rpm.ts#L116-L152","documentation":"When decoding a single-string metadata tag, the parser scans for the NUL terminator within the header data region; reaching the region end without one means the string is unterminated. Even though validateHeaderBody already checks termination, this second check guards the value-extraction path (e.g. signature vs main header divergence) before decoding.","triggerScenarios":"parseMainHeader calls readHeaderString for tag 1000/1001/1124/1125/1126 and the bytes from the tag offset to the end of the header data contain no 0 byte — typically because the header is truncated or its data size field is wrong.","commonSituations":"Incomplete downloads cutting off the header tail; corruption of the final NUL byte; headers rebuilt by tooling that miscounts dataSize.","solutions":["Re-download or rebuild the .rpm; the header data region is damaged.","Verify truncation by comparing file size with the published checksum.","Cross-check the header with `rpm -qp` to confirm corruption.","Catch ArchiveError and reject/skip the package in your processing loop."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (fileSize < manifestSize) throw new Error(\"download incomplete\");","typeGuard":null,"tryCatchPattern":"try {\n  const entries = await readRpm(source, options);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.includes(\"not NUL-terminated\")) {\n    return reDownloadAndRetry(file); // truncation is the usual cause\n  }\n  throw err;\n}","preventionTips":["Enforce complete downloads (Content-Length/checksum) before parsing.","Retry with a fresh download when truncation is suspected.","Parse at ingest time so corrupt files are caught early."],"tags":["rpm","archive","truncated","corrupt-file"],"backgroundTag":"rpm-header-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}