{"record":{"id":"eadeb39f50bc54a7","repo":"CherryHQ/cherry-studio","slug":"invalid-mcp-package-upload-file-buffer-cannot-be","errorCode":null,"errorMessage":"Invalid MCP package upload: file buffer cannot be empty","messagePattern":"Invalid MCP package upload: file buffer cannot be empty","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/ai/mcp/McpPackageService.ts","lineNumber":313,"sourceCode":"  }\n  if (!/^[A-Za-z0-9._ ()@+-]+$/.test(trimmedFileName)) {\n    throw new Error('Invalid MCP package upload: file name contains unsupported characters')\n  }\n  if (path.extname(trimmedFileName).toLowerCase() !== `.${packageFormat}`) {\n    throw new Error(`Invalid MCP package upload: expected a .${packageFormat} file`)\n  }\n\n  let buffer: Buffer\n  if (fileBuffer instanceof ArrayBuffer) {\n    buffer = Buffer.from(fileBuffer)\n  } else if (ArrayBuffer.isView(fileBuffer)) {\n    buffer = Buffer.from(fileBuffer.buffer, fileBuffer.byteOffset, fileBuffer.byteLength)\n  } else {\n    throw new Error('Invalid MCP package upload: file buffer must be an ArrayBuffer')\n  }\n\n  if (buffer.byteLength === 0) {\n    throw new Error('Invalid MCP package upload: file buffer cannot be empty')\n  }\n  if (buffer.byteLength > MCP_PACKAGE_UPLOAD_MAX_BYTES) {\n    throw new Error('Invalid MCP package upload: file exceeds the 100 MiB size limit')\n  }\n\n  return buffer\n}\n\nexport function applyPlatformOverrides(mcpConfig: any, extractDir: string, userConfig?: Record<string, any>): any {\n  const platform = process.platform\n  // Deep-copy the nested env so substitution never mutates the caller's manifest object.\n  const resolvedConfig = { ...mcpConfig, env: mcpConfig.env ? { ...mcpConfig.env } : mcpConfig.env }\n\n  // Apply platform-specific overrides\n  if (mcpConfig.platform_overrides && mcpConfig.platform_overrides[platform]) {\n    const override = mcpConfig.platform_overrides[platform]\n\n    // Override command if specified","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/McpPackageService.ts#L295-L331","documentation":"Thrown by validatePackageUploadPayload when fileBuffer.byteLength === 0 after converting to a Node Buffer. The guard catches an empty upload before it reaches the zip extractor, which would otherwise fail with a less obvious decompression error. The conversion handles ArrayBuffer and ArrayBuffer.isView (e.g. Uint8Array from file.arrayBuffer()) and checks the resulting buffer length.","triggerScenarios":"Renderer sent an empty ArrayBuffer (new ArrayBuffer(0)) or an empty Uint8Array. Typically the result of reading a File that has no data, or constructing the payload before the file was loaded.","commonSituations":"file.arrayBuffer() was called on a File that had been cleared; the upload ran before the file was fully read; a test fixture created an empty Blob and expected the service to reject it.","solutions":["On the renderer, await file.arrayBuffer() and verify byteLength > 0 before dispatching the IPC.","If byteLength is 0, re-read the File or prompt the user to reselect; the file handle may have been invalidated.","Add a frontend size guard (non-empty and under the 100 MiB limit) so the user gets immediate feedback."],"exampleFix":"// renderer - before\nconst buf = await file.arrayBuffer()\nawait upload(buf, file.name)\n// after\nconst buf = await file.arrayBuffer()\nif (buf.byteLength === 0) { setError('File is empty'); return }\nawait upload(buf, file.name)","handlingStrategy":"validation","validationCode":"function isNonEmptyBuffer(buf: ArrayBuffer | ArrayBufferView): boolean {\n  return buf.byteLength > 0\n}","typeGuard":"function isNonEmptyArrayBuffer(buf: unknown): boolean {\n  if (buf instanceof ArrayBuffer) return buf.byteLength > 0\n  if (ArrayBuffer.isView(buf as ArrayBufferView)) return (buf as ArrayBufferView).byteLength > 0\n  return false\n}","tryCatchPattern":null,"preventionTips":["On the renderer, check file.size > 0 before reading and dispatching.","Await file.arrayBuffer() and guard byteLength === 0 with a user-facing message.","In tests, never construct the IPC payload from an empty Blob."],"tags":["mcp","upload","validation","ipc"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}