{"record":{"id":"c27e8ec5a6e7e84c","repo":"can1357/oh-my-pi","slug":"unsupported-rar5-compression-algorithm-version-v","errorCode":null,"errorMessage":"Unsupported RAR5 compression algorithm version ${version}","messagePattern":"Unsupported RAR5 compression algorithm version (.+?)","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/rar/rar5-decoder.ts","lineNumber":168,"sourceCode":"\t\tthis.#history = new Uint8Array(0);\n\t\tthis.#reps = [0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff];\n\t\tthis.#lastLen = 0;\n\t\tthis.#main = new Huffman(MAIN_SIZE);\n\t\tthis.#dist = new Huffman(DIST_SIZE);\n\t\tthis.#align = new Huffman(ALIGN_SIZE);\n\t\tthis.#length = new Huffman(LEN_SIZE);\n\t\tthis.#useAlign = false;\n\t}\n\n\tdecode(\n\t\tpacked: Uint8Array,\n\t\tunpackedSize: number,\n\t\tdictionarySize: number,\n\t\tsolid: boolean,\n\t\tversion: number,\n\t): Uint8Array {\n\t\tif (version !== 0 && version !== 1) {\n\t\t\tthrow new ArchiveError(`Unsupported RAR5 compression algorithm version ${version}`);\n\t\t}\n\t\tif (!solid) this.reset();\n\t\tif (!Number.isSafeInteger(dictionarySize) || dictionarySize < 128 * 1024) fail(\"invalid dictionary size\");\n\t\tconst prior =\n\t\t\tthis.#history.byteLength > dictionarySize\n\t\t\t\t? this.#history.subarray(this.#history.byteLength - dictionarySize)\n\t\t\t\t: this.#history;\n\t\tconst data = new Uint8Array(prior.byteLength + unpackedSize + MAX_MATCH);\n\t\tdata.set(prior);\n\t\tlet outPos = prior.byteLength;\n\t\tconst outStart = outPos;\n\t\tconst outEnd = outStart + unpackedSize;\n\t\tconst filters: Filter[] = [];\n\t\tconst bits = new Bits(packed);\n\t\tconst main = this.#main;\n\t\tconst dist = this.#dist;\n\t\tconst align = this.#align;\n\t\tconst lenDecoder = this.#length;","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/rar/rar5-decoder.ts#L150-L186","documentation":"RAR5 archives store a per-file compression algorithm version; this decoder only implements versions 0 and 1. When a member header declares a newer algorithm version, the decoder refuses to guess and throws ArchiveError instead of producing corrupt output.","triggerScenarios":"Decoding a RAR5 member whose compression header field 'version' is >= 2 (or negative/garbage), typically via readRar/extracting an archive created by a newer RAR (RAR7+) using a newer compression algorithm.","commonSituations":"Opening archives produced by WinRAR 7.x with the new RAR7 compression format using a decoder that only supports RAR5 v0/v1; corrupted header bytes flipping the version field.","solutions":["Re-create the archive with WinRAR/unrar using RAR5 compression (not the RAR7/new algorithm) or store with -m0","Upgrade to a decoder/library version that supports the newer RAR5 algorithm version","Extract the member with the official unrar/WinRAR tool and re-pack before feeding it to this library"],"exampleFix":"// before: archive made with WinRAR 7 defaults (RAR7 algorithm) fails to decode\n// after: repack with RAR5-compatible compression\n// $ rar a -ma5 -m3 output.rar files/","handlingStrategy":"try-catch","validationCode":"// Pre-check RAR5 algorithm version from parsed metadata if available:\n// records where format===5 and version>1 will fail\nconst risky = records.some(r => r.format === 5 && r.version > 1);\nif (risky) console.warn('Archive uses unsupported RAR5 algorithm version; repack or use unrar');","typeGuard":"function isSupportedRar5Version(record: { format: number; version: number }): boolean {\n  return record.format !== 5 || record.version === 0 || record.version === 1;\n}","tryCatchPattern":"try {\n  const bytes = await reader.read(memberPath);\n} catch (err) {\n  if (err instanceof ArchiveError && /algorithm version/.test(err.message)) {\n    // fall back to external unrar tooling\n  }\n  throw err;\n}","preventionTips":["Create archives with -ma5 (not -ma7) when they will be consumed by this library","Prefer standard compression methods (-m1..-m5) over newer algorithm variants","Test archives with `unrar t` in CI before processing them"],"tags":["rar","archive","unsupported-version","compression"],"backgroundTag":"unsupported-archive-compression-version","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}