mihomo-party-org/clash-party · error · Error

Plugin file too large

Error message

Plugin file too large

What it means

readPluginFile enforces MAX_PLUGIN_FILE_BYTES: if stat().size exceeds the cap the file is rejected before any bytes are read. This prevents loading unreasonably large (possibly malicious or corrupted) plugin payloads into memory.

Source

Thrown at src/main/resolve/plugin/file.ts:19

import { open } from 'fs/promises'
import { basename, extname, resolve } from 'path'
import { MAX_PLUGIN_FILE_BYTES } from './constants'

export function findPluginFile(args: string[]): string | undefined {
  return args.find(
    (arg) => !arg.startsWith('-') && !arg.includes('://') && extname(arg).toLowerCase() === '.cpx'
  )
}

export async function readPluginFile(filePath: string): Promise<IPluginFilePayload> {
  if (extname(filePath).toLowerCase() !== '.cpx') throw new Error('Unsupported plugin file type')

  const resolvedPath = resolve(filePath)
  const handle = await open(resolvedPath, 'r')
  try {
    const stat = await handle.stat()
    if (!stat.isFile()) throw new Error('Plugin path is not a file')
    if (stat.size > MAX_PLUGIN_FILE_BYTES) throw new Error('Plugin file too large')

    // Read at most one byte beyond the limit so a file growing after stat cannot bypass the cap.
    const bytes = Buffer.alloc(MAX_PLUGIN_FILE_BYTES + 1)
    let length = 0
    while (length < bytes.length) {
      const { bytesRead } = await handle.read(bytes, length, bytes.length - length, null)
      if (bytesRead === 0) break
      length += bytesRead
    }
    if (length > MAX_PLUGIN_FILE_BYTES) throw new Error('Plugin file too large')

    return {
      name: basename(resolvedPath),
      fileBytesB64: bytes.subarray(0, length).toString('base64')
    }
  } finally {
    await handle.close()
  }

View on GitHub (pinned to 911e090537)

Solutions

  1. Obtain a fresh copy of the plugin under the size limit from a trusted source.
  2. Check the file size yourself (ls -l / stat) to confirm it exceeds the cap before retrying.
  3. Verify disk health if sizes look implausible (sparse/growing files).
Defensive patterns

Strategy: validation

Validate before calling

import { statSync } from 'node:fs'
import { MAX_PLUGIN_FILE_BYTES } from './plugin/file'
const st = statSync(pluginPath)
if (st.size > MAX_PLUGIN_FILE_BYTES) {
  throw new Error(`Plugin file exceeds ${MAX_PLUGIN_FILE_BYTES} bytes`)
}

Try / catch

try {
  const payload = await readPluginFile(pluginPath)
} catch (e) {
  if ((e as Error).message === 'Plugin file too large') {
    // re-download from a trusted source / report oversized file
  } else throw e
}

Prevention

When it happens

Trigger: Calling readPluginFile on a .cpx file whose on-disk size is greater than MAX_PLUGIN_FILE_BYTES at the time of stat().

Common situations: A corrupted/inflated download, someone replacing the plugin with a huge archive, or a disk issue producing a bogus file size.

Related errors


AI-assisted analysis of mihomo-party-org/clash-party@911e090537 (2026-08-30). Data as JSON: /api/errors/238cd83054b3d546. Report an issue: GitHub.