{"record":{"id":"b8746578e1685c0a","repo":"can1357/oh-my-pi","slug":"invalid-rar5-archive-reason","errorCode":null,"errorMessage":"Invalid RAR5 archive: ${reason}","messagePattern":"Invalid RAR5 archive: (.+?)","errorType":"validation","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/rar/rar5-decoder.ts","lineNumber":399,"sourceCode":"\t\t\t\twriteI32(data, pos, address);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction readI32(bytes: Uint8Array, offset: number): number {\n\treturn bytes[offset]! | (bytes[offset + 1]! << 8) | (bytes[offset + 2]! << 16) | (bytes[offset + 3]! << 24);\n}\n\nfunction writeI32(bytes: Uint8Array, offset: number, value: number): void {\n\tbytes[offset] = value;\n\tbytes[offset + 1] = value >>> 8;\n\tbytes[offset + 2] = value >>> 16;\n\tbytes[offset + 3] = value >>> 24;\n}\n\nfunction fail(reason: string): never {\n\tthrow new ArchiveError(`Invalid RAR5 archive: ${reason}`);\n}\n","sourceCodeStart":381,"sourceCodeEnd":401,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/rar/rar5-decoder.ts#L381-L401","documentation":"Generic guard used throughout the RAR4/RAR5 decoders: any structural inconsistency while parsing headers or huffman-coded streams (bad sizes, invalid tables, out-of-range deltas, truncated data) raises 'Invalid RAR5 archive: <reason>'. It signals the byte stream does not conform to the RAR5 format at the point of failure.","triggerScenarios":"parseRar5 or Rar5Decoder.decode() calling fail(reason) for malformed header sizes, invalid dictionary size (<128 KiB), filter ranges beyond unpacked size, bad huffman tables, or truncation mid-stream.","commonSituations":"Partially downloaded or truncated .rar files; passing a non-RAR file that coincidentally matched the 8-byte signature; bit-rotted archives on old storage; concatenated/multi-part archives opened without all volumes.","solutions":["Verify the archive integrity with `unrar t archive.rar` and re-download/re-copy if it fails","Ensure the full file (all volumes for multi-part sets) is present and complete","Confirm you are passing a genuine RAR5 file (starts with 'Rar!\\x1a\\x07\\x01\\x00') and not a renamed/other archive"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const head = new Uint8Array(await file.slice(0, 8).arrayBuffer());\nconst rar5Sig = [0x52,0x61,0x72,0x21,0x1a,0x07,0x01,0x00];\nif (!rar5Sig.every((b, i) => head[i] === b)) throw new Error('Not a RAR5 file');\nif (file.size < 64) throw new Error('File too small to be a valid RAR');","typeGuard":"function hasRar5Signature(head: Uint8Array): boolean {\n  return head.length >= 8 && head[0]===0x52 && head[1]===0x61 && head[2]===0x72 && head[3]===0x21\n    && head[4]===0x1a && head[5]===0x07 && head[6]===0x01 && head[7]===0x00;\n}","tryCatchPattern":"try {\n  const reader = await readRar(source, { limits });\n} catch (err) {\n  if (err instanceof ArchiveError && err.message.startsWith('Invalid RAR5 archive')) {\n    throw new Error(`Archive is corrupt or truncated: ${err.message}`);\n  }\n  throw err;\n}","preventionTips":["Verify file size against the publisher's expected size before parsing","Run `unrar t` on untrusted archives before programmatic processing","Ensure complete multi-volume sets are present before reading","Detect signature mismatch early: check the first 8 bytes before handing the source to the library"],"tags":["rar","corrupt-archive","parse-error","validation"],"backgroundTag":"corrupt-archive-data","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}