can1357/oh-my-pi · error · ArchiveError

Tar archive is too large to encode safely

Error message

Tar archive is too large to encode safely

What it means

concatBytes accumulates the total byte length of all tar parts and allocates one output buffer. If the running total exceeds Number.MAX_SAFE_INTEGER the library refuses to build an archive whose size cannot be represented safely in JavaScript numbers, rather than producing a corrupt buffer.

Source

Thrown at packages/utils/src/ar/tar.ts:653

	let length = body.byteLength + 2;
	for (;;) {
		const digits = String(length).length;
		const next = digits + 1 + body.byteLength;
		if (next === length) break;
		length = next;
	}
	const prefix = TEXT_ENCODER.encode(`${length} `);
	const record = new Uint8Array(length);
	record.set(prefix);
	record.set(body, prefix.byteLength);
	return record;
}

function concatBytes(parts: readonly Uint8Array[]): Uint8Array {
	let length = 0;
	for (const part of parts) {
		length += part.byteLength;
		if (!Number.isSafeInteger(length)) throw new ArchiveError("Tar archive is too large to encode safely");
	}
	const output = new Uint8Array(length);
	let offset = 0;
	for (const part of parts) {
		output.set(part, offset);
		offset += part.byteLength;
	}
	return output;
}

function makeHeader(
	name: Uint8Array,
	prefix: Uint8Array,
	size: number,
	mtime: number,
	mode: number,
	typeFlag: number,
): Uint8Array {

View on GitHub (pinned to 9690622007)

Solutions

  1. Audit the sizes passed into createTar; real archives are far below the limit
  2. Cap total archive size before encoding and split into multiple archives
  3. Check for arithmetic errors producing inflated part sizes
Defensive patterns

Strategy: validation

Validate before calling

let total = 0;
for (const [p, bytes] of members) total += bytes.byteLength + 512;
if (!Number.isSafeInteger(total)) throw new Error("Archive too large");

Try / catch

try {
	return await createTar(members);
} catch (err) {
	if (err instanceof ArchiveError && err.message.includes("too large")) {
		// split members into multiple archives
	}
	throw err;
}

Prevention

When it happens

Trigger: Encoding a tar from a members map whose combined (padded) entry and header bytes exceed Number.MAX_SAFE_INTEGER (~9 PB). Practically unreachable with real files; requires absurd input sizes or an arithmetic bug upstream.

Common situations: Feeding computed/attacker-controlled sizes that overflow; a bug multiplying padding or block counts; fuzzing the encoder.

Related errors


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