can1357/oh-my-pi · error · ArchiveError
Invalid tar member size
Error message
Invalid tar member size
What it means
readTarSize decodes the 12-byte size field of a tar header and validates the result. This throw means the decoded value is not a non-negative safe integer — typically a corrupted, non-octal, or absurdly large size field (including base-256 values overflowing safe-integer range). The parser refuses sizes it cannot trust to slice member data safely.
Source
Thrown at packages/utils/src/ar/tar.ts:136
let value = 0n;
if ((first & 0x80) !== 0) {
value = BigInt(first & 0x7f);
for (let index = 1; index < length; index++) {
value = (value << 8n) | BigInt(buffer[offset + index]!);
}
if ((first & 0x40) !== 0) value -= 1n << BigInt(length * 8 - 1);
} else {
for (let index = 0; index < length; index++) {
const byte = buffer[offset + index]!;
if (byte >= 0x30 && byte <= 0x37) value = value * 8n + BigInt(byte - 0x30);
}
}
return Number(value);
}
function readTarSize(buffer: Uint8Array, offset: number): number {
const size = readTarNumeric(buffer, offset, SIZE_LENGTH);
if (!Number.isSafeInteger(size) || size < 0) throw new ArchiveError("Invalid tar member size");
return size;
}
function paddedSize(size: number): number {
const remainder = size % BLOCK_SIZE;
const padded = size + (remainder === 0 ? 0 : BLOCK_SIZE - remainder);
if (!Number.isSafeInteger(padded)) throw new ArchiveError("Invalid tar member size");
return padded;
}
function parsePaxSize(value: string, field: string): number {
if (!/^\d+$/.test(value)) throw new ArchiveError(`Invalid tar ${field}`);
const size = Number(value);
if (!Number.isSafeInteger(size) || size < 0) throw new ArchiveError(`Invalid tar ${field}`);
return size;
}
function isZeroBlock(buffer: Uint8Array, offset: number): boolean {View on GitHub (pinned to 9690622007)
Solutions
- Verify the archive integrity (checksum, re-download, compare hashes) — this usually indicates real corruption.
- Confirm the file is actually a tar archive; use sniffTar before parsing.
- If you generate tar archives yourself, fix the writer: the size field must be zero-padded octal (e.g. '00000000000\0') or valid GNU base-256.
- Catch ArchiveError and report the archive as unrecoverable rather than retrying the same bytes.
Defensive patterns
Strategy: try-catch
Validate before calling
import { sniffTar } from "@oh-my-pi/pi-utils/ar/tar";
// pre-check: a header's size field must be octal digits or base-256
const sizeField = buffer.subarray(124, 136);
const looksOctal = [...sizeField].every(b => (b >= 0x30 && b <= 0x37) || b === 0 || b === 0x20);
if (!sniffTar(buffer) || !looksOctal) throw new Error("Suspicious or corrupt tar size field"); Try / catch
try {
const entries = readTarEntriesFromBuffer(buffer, options);
} catch (err) {
if (err instanceof ArchiveError && /Invalid tar member size/.test(err.message)) {
throw new Error("Archive is corrupt: member size field is not a valid octal/base-256 value");
}
throw err;
} Prevention
- Verify archive integrity (hash/checksum) before parsing untrusted files.
- Reject files that fail sniffTar instead of forcing a parse.
- If you write tar archives, test their output against GNU tar before shipping.
- Treat this error as fatal corruption — never retry the same bytes.
When it happens
Trigger: Parsing a tar header whose size field at offset 124 contains garbage (random bytes, ASCII text, or a base-256 encoded value exceeding Number.MAX_SAFE_INTEGER) — reached via the size accessor while indexing an archive with readTar/readTarEntriesFromBuffer.
Common situations: Corrupted downloads, files damaged in transfer/storage, misidentified files that pass a checksum by luck, or archives produced by broken/non-conforming tar writers.
Related errors
- Invalid tar numeric field
- Invalid tar octal value: ${value}
- Truncated embedded addon archive entry: ${filename}
- Unsafe embedded addon archive entry: ${filename}
- Unsupported embedded addon archive entry type ${typeflag}: $
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/128addf63b4e7584.
Report an issue: GitHub.