{"record":{"id":"267b02bfa6bb0762","repo":"can1357/oh-my-pi","slug":"invalid-rar-member-index","errorCode":null,"errorMessage":"Invalid RAR member index","messagePattern":"Invalid RAR member index","errorType":"validation","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/rar.ts","lineNumber":82,"sourceCode":"\t}\n\n\tasync read(index: number, size: number, memberPath: string): Promise<Uint8Array> {\n\t\tconst pending = this.#queue.then(async () => {\n\t\t\tif (!this.#cache.has(index)) await this.#decode(index);\n\t\t});\n\t\tthis.#queue = pending.catch(() => undefined);\n\t\tawait pending;\n\t\tconst bytes = this.#cache.get(index);\n\t\tif (!bytes) throw new ArchiveError(`Failed to extract RAR member '${memberPath}'`);\n\t\tif (bytes.byteLength !== size) {\n\t\t\tthrow new ArchiveError(`RAR member '${memberPath}' size mismatch (${bytes.byteLength} != ${size})`);\n\t\t}\n\t\treturn bytes.slice();\n\t}\n\n\tasync #decode(index: number): Promise<void> {\n\t\tconst target = this.#records[index];\n\t\tif (!target) throw new ArchiveError(\"Invalid RAR member index\");\n\t\tlet start = index;\n\t\tif (target.solid) {\n\t\t\twhile (start > 0 && this.#records[start]!.solid && this.#records[start - 1]!.format === target.format) start--;\n\t\t}\n\t\tconst rar4Decoder = new Rar4Decoder();\n\t\tconst rar5Decoder = new Rar5Decoder();\n\t\tfor (let current = start; current <= index; current++) {\n\t\t\tconst record = this.#records[current]!;\n\t\t\tif (record.isDirectory) continue;\n\t\t\tassertArchiveMemberSize(record.unpackedSize, record.path, this.#limits);\n\t\t\tif (record.method === 0 && record.packedSize !== record.unpackedSize) {\n\t\t\t\tcorrupt(\"stored member size mismatch\");\n\t\t\t}\n\t\t\tif (record.method > 5) {\n\t\t\t\tthrow new ArchiveError(\n\t\t\t\t\trecord.format === 4\n\t\t\t\t\t\t? `Unsupported RAR4 compression method 0x${(record.method + 0x30).toString(16)} for '${record.path}'`\n\t\t\t\t\t\t: `Unsupported RAR5 compression method ${record.method} for '${record.path}'`,","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/rar.ts#L64-L100","documentation":"#decode(index) is the internal worker behind read(); it throws when this.#records[index] is undefined, i.e. the requested index does not correspond to any member found while indexing the archive.","triggerScenarios":"An internal path resolving a memberPath to an index that no longer exists in the record table — effectively a lookup inconsistency between the directory listing and the records array (normally unreachable from the public API).","commonSituations":"Only via library bugs or misuse of internal APIs; not something a normal caller of read(memberPath) can trigger directly.","solutions":["Upgrade/retry with the public read(memberPath) API using a path returned by the archive listing","If reproducible, file a bug with the archive sample — this indicates an index/record inconsistency"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const members = reader.list();\nconst paths = new Set(members.map(m => m.path));\nif (!paths.has(memberPath)) throw new Error(`Unknown member: ${memberPath}`);","typeGuard":"function memberExists(members: { path: string }[], path: string): boolean {\n  return members.some(m => m.path === path);\n}","tryCatchPattern":"try {\n  const bytes = await reader.read(memberPath);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message === 'Invalid RAR member index') {\n    throw new Error(`Member not found in archive: ${memberPath}`);\n  }\n  throw err;\n}","preventionTips":["Always look up members through the archive's own listing rather than cached/stale paths","Re-list members after re-opening an archive; don't reuse indexes across reader instances","Report reproducible occurrences upstream — this indicates an internal inconsistency"],"tags":["rar","archive","invalid-index","internal"],"backgroundTag":"archive-member-extraction-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}