can1357/oh-my-pi · error · ArchiveError
Archive is too large to read safely
Error message
Archive is too large to read safely
What it means
assertInMemorySize guards every reader that must fully materialize an archive (arj, cab, cpio, deb tar members, etc.). This variant fires when the claimed size is not a safe non-negative integer — a corrupted size field, integer overflow, or garbage metadata — so the size itself is untrustworthy and reading would be unsafe even before comparing against the configured limit.
Source
Thrown at packages/utils/src/ar/limits.ts:38
/** Max byte length of a member path or link target. */
maxPathBytes: number;
/** Max symlink rewrites while resolving one path. */
maxLinkDepth: number;
}
export const DEFAULT_ARCHIVE_LIMITS: ArchiveLimits = {
maxEntries: 1_000_000,
maxInMemorySize: 256 * 1024 * 1024,
maxIndexSize: 64 * 1024 * 1024,
maxMemberSize: 64 * 1024 * 1024,
maxPathBytes: 4096,
maxLinkDepth: 40,
};
/** Reject an archive that would be fully materialized beyond `maxInMemorySize`. */
export function assertInMemorySize(size: number, limits: ArchiveLimits): void {
if (!Number.isSafeInteger(size) || size < 0) {
throw new ArchiveError("Archive is too large to read safely");
}
if (size > limits.maxInMemorySize) {
throw new ArchiveError(
`Archive is too large to read in memory (${formatBytes(size)} > ${formatBytes(limits.maxInMemorySize)} limit)`,
);
}
}
/** Reject archive metadata (index/header) beyond `maxIndexSize`. */
export function assertIndexSize(size: number, limits: ArchiveLimits, what: string): void {
if (!Number.isSafeInteger(size) || size < 0) {
throw new ArchiveError(`Invalid archive: ${what} has an invalid size`);
}
if (size > limits.maxIndexSize) {
throw new ArchiveError(
`Archive ${what} is too large (${formatBytes(size)} > ${formatBytes(limits.maxIndexSize)} limit)`,
);
}View on GitHub (pinned to 9690622007)
Solutions
- Verify the archive's integrity (checksum) and re-obtain a good copy; the size field is almost certainly corrupt
- Check the archive header manually to see whether the declared size is sane (compare with actual file size)
- Validate/re-encode the archive with its native tooling (cabextract -l, cpio -it < file) to detect structural damage
- If you feed computed sizes yourself (offsets/lengths), audit that arithmetic for overflow or unit errors
Example fix
// before: size read from corrupt header
await readCpio(bytes); // ArchiveError: Archive is too large to read safely
// after: sanity-check before reading
const headerSize = readSizeField(bytes);
if (!Number.isSafeInteger(headerSize) || headerSize < 0 || headerSize > bytes.byteLength * 8) {
throw new Error('implausible archive size field');
}
await readCpio(bytes); Defensive patterns
Strategy: validation
Validate before calling
function plausibleSize(size, fileBytes) {
return Number.isSafeInteger(size) && size >= 0 && size <= fileBytes * 16; // inflate headroom
}
// call readers only after validating header-derived sizes
if (!plausibleSize(headerSize, bytes.byteLength)) throw new Error('corrupt size field'); Type guard
function isSafeSize(size) {
return typeof size === 'number' && Number.isSafeInteger(size) && size >= 0;
} Try / catch
try {
entries = await readCabArchive(buf);
} catch (err) {
if (err instanceof ArchiveError && err.message === 'Archive is too large to read safely') {
// corrupt/overflowed size field -> treat as corrupt archive
} else throw err;
} Prevention
- Validate archive headers/checksums before reading untrusted files
- Never feed sizes you computed with unchecked arithmetic
- Distinguish this 'unsafe size' error from the limit-exceeded variant when triaging
When it happens
Trigger: Calling any buffer-materializing archive reader (readArj, readCabArchive, readCpio, readDeb's decompressDebTar, etc.) when a size value fed to assertInMemorySize is NaN, negative, or exceeds Number.MAX_SAFE_INTEGER — typically from a corrupted header/length field or bad arithmetic on offsets.
Common situations: Corrupt or truncated archive headers, malicious archives with overflowed 64-bit size fields, files larger than ~9 petabytes mis-parsed due to field-width bugs, or a caller passing wrong limits/offsets causing bogus computed sizes.
Related errors
- Archive is too large to read in memory (${formatBytes(size)}
- Invalid ARJ archive: too many extended headers
- ASAR archive is too large to encode in memory
- Invalid CAB archive: reserved CFHEADER fields must be zero
- Invalid CAB archive: CFFILE table offset is out of bounds
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/f246e5e36fe06ee5.
Report an issue: GitHub.