can1357/oh-my-pi · error · ArchiveError

Invalid RAR5 UTF-8 link target

Error message

Invalid RAR5 UTF-8 link target

What it means

The link target stored in a RAR5 redirection extra record (type 5) must be valid UTF-8. When UTF8.decode fails on the target bytes, the library throws this ArchiveError instead of producing a record with a garbled symlink target — indicating corruption or a malformed archive.

Source

Thrown at packages/utils/src/ar/rar.ts:404

							need(extraCursor.offset, 4, extra.end, "Unix modification time");
							mtimeMs = readUInt32LE(bytes, extraCursor.offset) * 1000;
						} else {
							need(extraCursor.offset, 8, extra.end, "Windows modification time");
							mtimeMs = filetimeMs(bytes, extraCursor.offset);
						}
					}
				} else if (extra.type === 5) {
					const redirectionType = readVint(bytes, extraCursor, extra.end, "redirection type");
					readVint(bytes, extraCursor, extra.end, "redirection flags");
					const targetSize = readVint(bytes, extraCursor, extra.end, "link target size");
					assertArchivePathBytes(targetSize, "link target", options.limits.maxPathBytes);
					need(extraCursor.offset, targetSize, extra.end, "link target");
					if (redirectionType < 1 || redirectionType > 5)
						throw new ArchiveError(`Unsupported RAR5 redirection type ${redirectionType}`);
					try {
						linkTarget = UTF8.decode(bytes.subarray(extraCursor.offset, extraCursor.offset + targetSize));
					} catch {
						throw new ArchiveError("Invalid RAR5 UTF-8 link target");
					}
				}
			}
			if (type === 2) {
				assertArchiveMemberSize(unpackedSize, rawPath, options.limits);
				const path = normalizeArchiveEntryPath(rawPath);
				if (path) {
					let linkResolveTarget: boolean | undefined;
					if (linkTarget !== undefined) {
						const canonical = canonicalLinkTarget(path, linkTarget);
						linkTarget = canonical.target;
						linkResolveTarget = canonical.resolveTarget;
					}
					const isDirectory = (fileFlags & 1) !== 0;
					records.push({
						format: 5,
						path,
						dataStart,

View on GitHub (pinned to 9690622007)

Solutions

  1. Validate the archive with `unrar t` and re-download/re-create if corrupt
  2. Repair with WinRAR's repair or `rar r` if a recovery record exists
  3. Re-create the archive, ensuring symlinks/paths are stored correctly
Defensive patterns

Strategy: try-catch

Try / catch

try {
  const records = readRar(bytes);
} catch (err) {
  if (err instanceof ArchiveError && err.message.includes('Invalid RAR5 UTF-8 link target')) {
    throw new Error('Archive link metadata is corrupt');
  } else throw err;
}

Prevention

When it happens

Trigger: A file header contains a redirection extra record whose targetSize bytes fail UTF-8 validation — corrupted archives, wrong extra-record boundaries due to corruption, or crafted/malformed files.

Common situations: Damaged downloads; archives edited or re-assembled by broken tooling; fuzzed or malicious archive files; transferring archives in text mode corrupting bytes.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/7c58077246d8b5df. Report an issue: GitHub.