{"record":{"id":"6cf67f503c36c6ac","repo":"can1357/oh-my-pi","slug":"invalid-arj-main-header","errorCode":null,"errorMessage":"Invalid ARJ main header","messagePattern":"Invalid ARJ main header","errorType":"exception","errorClass":"ArchiveError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/ar/arj.ts","lineNumber":245,"sourceCode":"\tsource: ByteSource,\n\toptions: FormatReadOptions,\n): Promise<ArchiveIndexEntry[]> => {\n\tassertInMemorySize(source.size, options.limits);\n\tlet bytes: Uint8Array;\n\ttry {\n\t\tbytes = await readAllBytes(source);\n\t} catch (error) {\n\t\tif (error instanceof ArchiveError) throw error;\n\t\tthrow new ArchiveError(`Unable to read ARJ archive: ${error instanceof Error ? error.message : String(error)}`);\n\t}\n\tif (bytes.byteLength !== source.size) throw new ArchiveError(\"Invalid ARJ archive: truncated data\");\n\tif (!sniffArj(bytes)) throw new ArchiveError(\"Invalid ARJ archive header\");\n\n\tconst main = parseArjBlock(bytes, 0, options);\n\tif (main.isEnd) throw new ArchiveError(\"Invalid ARJ archive: missing main header\");\n\tconst mainFirstHeaderSize = bytes[main.bodyStart]!;\n\tif (mainFirstHeaderSize < 30 || mainFirstHeaderSize > main.bodySize || bytes[main.bodyStart + 6] !== 2) {\n\t\tthrow new ArchiveError(\"Invalid ARJ main header\");\n\t}\n\tconst mainFlags = bytes[main.bodyStart + 4]!;\n\tif ((mainFlags & 0x01) !== 0) throw new ArchiveError(\"Encrypted ARJ archives are unsupported\");\n\tif ((mainFlags & 0x04) !== 0) throw new ArchiveError(\"Multi-volume ARJ archives are unsupported\");\n\n\tconst entries: ArchiveIndexEntry[] = [];\n\tlet offset = main.nextOffset;\n\tlet metadataSize = main.metadataSize;\n\tlet parsedCount = 0;\n\tfor (;;) {\n\t\tconst block = parseArjBlock(bytes, offset, options);\n\t\tmetadataSize += block.metadataSize;\n\t\tassertIndexSize(metadataSize, options.limits, \"index\");\n\t\tif (block.isEnd) break;\n\t\tassertEntryCount(++parsedCount, options.limits);\n\t\tconst firstHeaderSize = bytes[block.bodyStart]!;\n\t\tif (firstHeaderSize < 30 || firstHeaderSize > block.bodySize) throw new ArchiveError(\"Invalid ARJ local header\");\n\t\tconst hostOs = bytes[block.bodyStart + 3]!;","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/ar/arj.ts#L227-L263","documentation":"This ArchiveError is thrown when the ARJ main header's first-header-size byte is out of range (< 30 or larger than the basic header body) or its archiver-version byte (offset 6) is not 2. The signature and header CRC passed, but the main header content is structurally invalid for this reader.","triggerScenarios":"Calling readArj on an archive whose main header was crafted by a non-standard writer, whose version field is not 2, or whose header size bytes were corrupted after the CRC passed (unlikely) — detected via bytes[bodyStart] and bytes[bodyStart+6].","commonSituations":"Archives from obscure/buggy ARJ clones, files hand-patched, corruption within the header body, or format variants (e.g. some security-enhanced ARJ versions) not matching the expected layout.","solutions":["Verify the archive with the official arj tool to confirm whether it is standard-compliant.","Recreate the archive with standard ARJ or a well-known compatible tool.","Check the producing tool's version; security-enhanced ARJ variants may need their own reader.","If corruption is suspected, re-download and compare checksums."],"exampleFix":"// before\nconst entries = await readArj(source, options);\n// after\ntry {\n  const entries = await readArj(source, options);\n} catch (e) {\n  if (e instanceof ArchiveError && e.message === 'Invalid ARJ main header') {\n    throw new Error('archive main header is malformed or from an unsupported ARJ variant; re-pack with standard ARJ');\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// main header body byte 6 must be the archiver version (2)\n// and byte 0 the first-header size (>= 30) — verify after sniff\nif (bytes[4] < 30 || bytes[4 + u16(bytes, 2)] === undefined || bytes[4 + 6] !== 2) {\n  throw new Error('non-standard ARJ main header; re-pack with standard ARJ');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const entries = await readArj(source, options);\n} catch (e) {\n  if (e instanceof ArchiveError && e.message === 'Invalid ARJ main header') {\n    throw new Error('unsupported or malformed ARJ main header; use a standard-compliant archive');\n  }\n  throw e;\n}","preventionTips":["Prefer archives produced by standard ARJ or well-known compatible tools","Reject archives from unknown/obscure archiver clones up front","Verify with the official arj tool before automated processing"],"tags":["archive","arj","header","corruption"],"backgroundTag":"invalid-archive-format","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}