can1357/oh-my-pi · error · ArchiveError

Invalid CAB archive: file has an invalid DOS timestamp

Error message

Invalid CAB archive: file has an invalid DOS timestamp

What it means

dosTimestamp converts packed 16-bit DOS date/time fields from CFFILE entries into an epoch timestamp, and rejects field values that decode to an impossible calendar date (month 0 or >12, day 0 or >31, hour >23, minute/second out of range) instead of returning a garbage Date. Zero date AND time means 'no timestamp' and is permitted; any other invalid combination throws.

Source

Thrown at packages/utils/src/ar/cab.ts:96

function decodeName(bytes: Uint8Array, utf8: boolean): string {
	try {
		return utf8 ? UTF8_FATAL_DECODER.decode(bytes) : LEGACY_NAME_DECODER.decode(bytes);
	} catch {
		throw new ArchiveError("Invalid CAB archive: file name is not valid UTF-8");
	}
}

function dosTimestamp(date: number, time: number): number | undefined {
	if (date === 0 && time === 0) return undefined;
	const year = 1980 + (date >>> 9);
	const month = (date >>> 5) & 0x0f;
	const day = date & 0x1f;
	const hour = time >>> 11;
	const minute = (time >>> 5) & 0x3f;
	const second = (time & 0x1f) * 2;
	if (month < 1 || month > 12 || day < 1 || day > 31 || hour > 23 || minute > 59 || second > 59) {
		throw new ArchiveError("Invalid CAB archive: file has an invalid DOS timestamp");
	}
	return new Date(year, month - 1, day, hour, minute, second).getTime();
}

function modeFromAttributes(attributes: number, directory: boolean): number {
	if (directory) return 0o040755;
	let permissions = attributes & ATTRIBUTE_READ_ONLY ? 0o444 : 0o644;
	if (attributes & ATTRIBUTE_EXECUTE) permissions |= 0o111;
	return 0o100000 | permissions;
}

class CabFolder {
	readonly #source: ByteSource;
	readonly #description: CabFolderDescription;
	readonly #dataReserveSize: number;
	readonly #limits: ArchiveLimits;
	#decoded?: Promise<Uint8Array>;

View on GitHub (pinned to 9690622007)

Solutions

  1. Identify the offending entry and re-stamp it with a valid DOS timestamp, then rebuild the CAB (touch the source files and re-pack).
  2. Inspect the raw uDate/uTime words in a hex dump to confirm which field is out of range.
  3. If the archive comes from a known-buggy tool, re-create it with cabextract/lcab or a standard Windows archiver.
  4. If corruption is suspected, verify the CAB's integrity (cabextract -t) and re-transfer the file.
  5. If you cannot fix the source, extract with a lenient external tool and feed the extracted files to your pipeline instead of the CAB.

Example fix

// before: CAB with uDate=0xFFFF fails dosTimestamp
const table = await reader.fileTable(); // throws
// after: normalize timestamps before packing
// $ touch -d '2024-01-15 10:00' src/* && lcab src/ fixed.cab
const table = await openCab('fixed.cab').fileTable();
Defensive patterns

Strategy: validation

Validate before calling

// Validate DOS date/time words yourself before handing the archive to the reader
function validDosStamp(date: number, time: number): boolean {
  if (date === 0 && time === 0) return true;
  const month = (date >>> 5) & 0x0f, day = date & 0x1f;
  const hour = time >>> 11, minute = (time >>> 5) & 0x3f, second = (time & 0x1f) * 2;
  return month >= 1 && month <= 12 && day >= 1 && day <= 31 && hour <= 23 && minute <= 59 && second <= 59;
}

Try / catch

try {
  return await readCabArchive(bytes);
} catch (err) {
  if (err instanceof ArchiveError && err.message.includes('invalid DOS timestamp')) {
    throw new Error('CAB contains out-of-range file timestamps — re-stamp and re-pack the archive');
  }
  throw err;
}

Prevention

When it happens

Trigger: fileTable()/readCabArchive() encountering a CFFILE whose uDate/uTime fields were not zero but contain bit patterns that decode to an invalid calendar value — e.g. month field = 0 with a nonzero time, or day = 0.

Common situations: Archives produced by buggy or nonstandard CAB writers that store sentinel values like 0xFFFF in timestamps; bit-flipped corruption in the header region; files stamped with values generated by hand-rolled packers that mishandle DOS date packing.

Related errors


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