{"record":{"id":"b3f353f8a9957861","repo":"paperclipai/paperclip","slug":"invalid-zip-archive-malformed-central-directory-r","errorCode":null,"errorMessage":"Invalid zip archive: malformed central directory record.","messagePattern":"Invalid zip archive: malformed central directory record\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/src/portability-zip.ts","lineNumber":104,"sourceCode":"//     to exactly the declared directory size; and\n//   • every record references a real local file header, and the record count\n//     equals both the EOCD's declared count and the local entries parsed.\nfunction validateCentralDirectory(bytes: Uint8Array, eocdOffset: number, localHeaderCount: number) {\n  const declaredEntryCount = readUint16(bytes, eocdOffset + 10);\n  const centralDirectorySize = readUint32(bytes, eocdOffset + 12);\n  const centralDirectoryStart = readUint32(bytes, eocdOffset + 16);\n  if (centralDirectoryStart > eocdOffset || centralDirectoryStart + centralDirectorySize !== eocdOffset) {\n    throw new Error(\n      \"Invalid zip archive: central directory location is inconsistent (truncated or forged).\",\n    );\n  }\n\n  const directoryEnd = centralDirectoryStart + centralDirectorySize;\n  let cursor = centralDirectoryStart;\n  let recordCount = 0;\n  while (cursor < directoryEnd) {\n    if (cursor + 46 > directoryEnd || readUint32(bytes, cursor) !== CENTRAL_DIRECTORY_SIGNATURE) {\n      throw new Error(\"Invalid zip archive: malformed central directory record.\");\n    }\n    const fileNameLength = readUint16(bytes, cursor + 28);\n    const extraFieldLength = readUint16(bytes, cursor + 30);\n    const commentLength = readUint16(bytes, cursor + 32);\n    const localHeaderOffset = readUint32(bytes, cursor + 42);\n    if (localHeaderOffset + 4 > bytes.length || readUint32(bytes, localHeaderOffset) !== LOCAL_FILE_SIGNATURE) {\n      throw new Error(\"Invalid zip archive: central directory references a missing local entry.\");\n    }\n    cursor += 46 + fileNameLength + extraFieldLength + commentLength;\n    recordCount += 1;\n  }\n\n  if (cursor !== directoryEnd) {\n    throw new Error(\"Invalid zip archive: central directory size does not match its records.\");\n  }\n  if (recordCount !== declaredEntryCount || recordCount !== localHeaderCount) {\n    throw new Error(\n      `Invalid zip archive: central directory declares ${declaredEntryCount} entries but ${localHeaderCount} local entries were read (truncated or corrupt).`,","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/packages/shared/src/portability-zip.ts#L86-L122","documentation":"Error \"Invalid zip archive: malformed central directory record.\" thrown in paperclipai/paperclip.","triggerScenarios":"Thrown at packages/shared/src/portability-zip.ts:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-create the archive with a standard zip tool; the central directory is malformed."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}