{"record":{"id":"c6a4ac9303bb690c","repo":"can1357/oh-my-pi","slug":"invalid-rar4-archive-reason","errorCode":null,"errorMessage":"Invalid RAR4 archive: ${reason}","messagePattern":"Invalid RAR4 archive: (.+?)","errorType":"validation","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/rar/rar4-decoder.ts","lineNumber":458,"sourceCode":"\tfor (let position = 0; position < size; ) {\n\t\tconst symbol = preTable.decode(bits);\n\t\tif (symbol < 16) {\n\t\t\tlengths[position] = (symbol + previous[position]!) & 15;\n\t\t\tposition++;\n\t\t} else if (symbol === 16 || symbol === 17) {\n\t\t\tlet count = bits.read(symbol === 16 ? 3 : 7) + (symbol === 16 ? 3 : 11);\n\t\t\tconst value = position === 0 ? 0 : lengths[position - 1]!;\n\t\t\twhile (count-- > 0 && position < size) lengths[position++] = value;\n\t\t} else {\n\t\t\tlet count = bits.read(symbol === 18 ? 3 : 7) + (symbol === 18 ? 3 : 11);\n\t\t\twhile (count-- > 0 && position < size) lengths[position++] = 0;\n\t\t}\n\t}\n\treturn lengths;\n}\n\nfunction corrupt(reason: string): never {\n\tthrow new ArchiveError(`Invalid RAR4 archive: ${reason}`);\n}\n","sourceCodeStart":440,"sourceCodeEnd":460,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/rar/rar4-decoder.ts#L440-L460","documentation":"corrupt() is the RAR4 decoder's central malformed-data handler: any structural violation while parsing or decoding a RAR4 stream — bad Huffman tables, invalid block types, out-of-range offsets, truncated data, bad filter ranges — surfaces as 'Invalid RAR4 archive: <reason>' with a specific reason string. It signals the byte stream does not conform to the RAR4 format at that point.","triggerScenarios":"Any RAR4 decode path calling corrupt(reason): invalid length/Huffman tables, packed-size overflow, ranges where start+blockSize > unpackedSize, misaligned or truncated bit streams, inconsistent header fields.","commonSituations":"Partially downloaded or truncated .rar files; bit-rotted archives on old media; deliberately fuzzed archives; extracting a multi-part RAR without all volumes present.","solutions":["Re-obtain the archive and verify checksums/size — truncation is the most common cause.","For multi-part RARs, ensure every volume (.part1.rar ... .partN.rar) is present and named correctly.","Validate the archive with an independent tool (unrar t archive.rar or 7z t) to confirm corruption before blaming this library.","Read the embedded reason string — it pinpoints which structural invariant failed (tables, ranges, alignment) and guides whether repair is possible (e.g. `rar r` repair)."],"exampleFix":"// before (shell)\nnode extract.js partial.part2.rar\n// after (shell)\nunrar t archive.part1.rar   # verify integrity first\nnode extract.js archive.part1.rar  # run from part1 with all volumes present","handlingStrategy":"try-catch","validationCode":"// Verify integrity before extraction:\nconst size = (await Bun.file(p).size);\nif (size === 0) throw new Error(`${p} is empty/truncated`);\n// and for multi-part sets ensure all volumes exist:\nif (await missingRarVolumes(p)) throw new Error(`${p} is missing volumes`);","typeGuard":null,"tryCatchPattern":"try {\n  await extractArchive(p, dest);\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.startsWith(\"Invalid RAR4 archive:\")) {\n    // read err.message's reason, offer repair (`rar r`) or re-download to the user\n  }\n  throw err;\n}","preventionTips":["Check file size and checksums against the source before extraction.","For multi-part RARs, verify all volumes are present and run from part1.","Validate archives with `unrar t` / `7z t` in pipelines before automated decoding.","Never retry extraction blindly on corrupt-data errors — surface the reason to the user."],"tags":["archive","rar","rar4","corrupt-data","parsing"],"backgroundTag":"corrupt-archive-data","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}