vercel-labs/skills · error · Error

Invalid zip central directory size

Error message

Invalid zip central directory size

What it means

readZipArchive tracks the byte offset while walking central directory entries and, after the loop, requires offset to equal centralDirectory.offset + centralDirectory.size exactly. If parsing consumed more or fewer bytes than the central directory claims, the zip's structure is inconsistent (extra data, miscounted entries, or trailing junk inside the central directory region). The library refuses to guess and aborts.

Source

Thrown at src/archive.ts:397

    } else if (method === 8) {
      contents = inflateRawSync(compressed, {
        maxOutputLength: uncompressedSize + 1,
      });
    } else {
      throw new Error(`Unsupported zip compression method: ${method}`);
    }

    if (contents.byteLength !== uncompressedSize) {
      throw new Error('Zip entry size mismatch');
    }
    if (crc32(contents) !== expectedChecksum) {
      throw new Error('Zip entry checksum mismatch');
    }
    files.set(fileName, new Uint8Array(contents));
  }

  if (offset !== centralDirectory.offset + centralDirectory.size) {
    throw new Error('Invalid zip central directory size');
  }

  return files;
}

View on GitHub (pinned to 435076e789)

Solutions

  1. Validate the file externally (unzip -t) to confirm structural damage
  2. Re-download or regenerate the archive from the canonical source
  3. Re-zip the content with a standard tool (zip -r or tar via git archive) and use the fresh artifact
  4. If it reproduces with a valid zip, open an issue with the file

Example fix

# before
skills add ./broken.zip  # Invalid zip central directory size

# after
mkdir tmp && unzip broken.zip -d tmp   # salvage contents
cd tmp && zip -r ../fixed.zip .
skills add ../fixed.zip
Defensive patterns

Strategy: try-catch

Validate before calling

// Rough structural pre-check: EOCD signature must exist
import { readFileSync } from 'node:fs';
function looksLikeZip(path: string): boolean {
  const buf = readFileSync(path);
  return buf.lastIndexOf(Buffer.from([0x50, 0x4b, 0x05, 0x06])) !== -1; // EOCD
}

Type guard

null

Try / catch

try {
  await extractArchive(file);
} catch (err) {
  if (err instanceof Error && err.message === 'Invalid zip central directory size') {
    // fall back to system unzip, which tolerates more zip quirks
  } else throw err;
}

Prevention

When it happens

Trigger: Extracting a zip whose central directory size field disagrees with the actual serialized entry records — zips with appended/edited central directories, pre-zip64 files near size limits, or archives modified by tools that rewrite headers imprecisely.

Common situations: Archives that were binary-patched or re-signed, files concatenated with other data, corrupted downloads, or archivers emitting nonstandard central directories.

Related errors


AI-assisted analysis of vercel-labs/skills@435076e789 (2026-08-28). Data as JSON: /api/errors/9f03d6b270d8f4a9. Report an issue: GitHub.