{"record":{"id":"9f03d6b270d8f4a9","repo":"vercel-labs/skills","slug":"invalid-zip-central-directory-size","errorCode":null,"errorMessage":"Invalid zip central directory size","messagePattern":"Invalid zip central directory size","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/archive.ts","lineNumber":397,"sourceCode":"    } else if (method === 8) {\n      contents = inflateRawSync(compressed, {\n        maxOutputLength: uncompressedSize + 1,\n      });\n    } else {\n      throw new Error(`Unsupported zip compression method: ${method}`);\n    }\n\n    if (contents.byteLength !== uncompressedSize) {\n      throw new Error('Zip entry size mismatch');\n    }\n    if (crc32(contents) !== expectedChecksum) {\n      throw new Error('Zip entry checksum mismatch');\n    }\n    files.set(fileName, new Uint8Array(contents));\n  }\n\n  if (offset !== centralDirectory.offset + centralDirectory.size) {\n    throw new Error('Invalid zip central directory size');\n  }\n\n  return files;\n}\n","sourceCodeStart":379,"sourceCodeEnd":402,"githubUrl":"https://github.com/vercel-labs/skills/blob/435076e78988e1e6ec40d00b0b1d76bdbbc5419a/src/archive.ts#L379-L402","documentation":"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.","triggerScenarios":"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.","commonSituations":"Archives that were binary-patched or re-signed, files concatenated with other data, corrupted downloads, or archivers emitting nonstandard central directories.","solutions":["Validate the file externally (unzip -t) to confirm structural damage","Re-download or regenerate the archive from the canonical source","Re-zip the content with a standard tool (zip -r or tar via git archive) and use the fresh artifact","If it reproduces with a valid zip, open an issue with the file"],"exampleFix":"# before\nskills add ./broken.zip  # Invalid zip central directory size\n\n# after\nmkdir tmp && unzip broken.zip -d tmp   # salvage contents\ncd tmp && zip -r ../fixed.zip .\nskills add ../fixed.zip","handlingStrategy":"try-catch","validationCode":"// Rough structural pre-check: EOCD signature must exist\nimport { readFileSync } from 'node:fs';\nfunction looksLikeZip(path: string): boolean {\n  const buf = readFileSync(path);\n  return buf.lastIndexOf(Buffer.from([0x50, 0x4b, 0x05, 0x06])) !== -1; // EOCD\n}","typeGuard":"null","tryCatchPattern":"try {\n  await extractArchive(file);\n} catch (err) {\n  if (err instanceof Error && err.message === 'Invalid zip central directory size') {\n    // fall back to system unzip, which tolerates more zip quirks\n  } else throw err;\n}","preventionTips":["Never binary-patch or append data to zip files","Regenerate archives with standard tools instead of editing them in place"],"tags":["zip","central-directory","structure","corruption"],"backgroundTag":"archive-corruption-detected","analyzedSha":"435076e78988e1e6ec40d00b0b1d76bdbbc5419a","analyzedAt":"2026-08-28T17:47:53.369Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}