affaan-m/ECC · error

Input exceeds file limit.

Error message

Input exceeds file limit.

What it means

readBounded reads a file with a hard byte budget (default MAX_BYTES) to prevent memory exhaustion and symlink/device attacks. It throws 'Input exceeds file limit.' when the file's stat size exceeds the limit or the streamed read ends up larger than the budget.

Solutions

  1. Check the file size (ls -lh) and compare against MAX_BYTES in coordination-inventory.js.
  2. Prune/compact the store file — archive completed work items so the file fits the budget.
  3. Pass a larger explicit limit argument to readBounded if the data legitimately needs it.
  4. Verify config points at the intended store file, not an oversized log or dump.

Example fix

// before
const data = readBounded(file); // default MAX_BYTES
// after
const data = readBounded(file, 10 * 1024 * 1024); // 10MB budget
// or prune the store until stat.size <= MAX_BYTES
Defensive patterns

Strategy: validation

Validate before calling

const stat = fs.statSync(file);
if (stat.size > MAX_BYTES) throw new Error(`${file} is ${stat.size}B, exceeds ${MAX_BYTES}B limit — prune or raise limit.`);

Type guard

function withinBudget(file, limit = MAX_BYTES) { try { return fs.statSync(file).size <= limit; } catch { return false; } }

Try / catch

try { const data = readBounded(file); } catch (e) {
  if (e.message === 'Input exceeds file limit.') { pruneStore(file); return readBounded(file); }
  throw e;
}

Prevention

When it happens

Trigger: readJson/data reading a store or inventory file larger than MAX_BYTES; a corrupted/append-only store that grew unbounded; caller passing a tiny custom limit on a normal file; a device/FIFO-like file failing the isFile check path where size check trips first.

Common situations: Long-running project where coordination store accumulated thousands of items past the size cap; passing the wrong (small) limit argument; pointing the inventory at a large log file by config mistake.

Understand the failure class

Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/c3314f3fafee23c3. Report an issue: GitHub.

Appendix: source

Thrown at scripts/lib/coordination-inventory.js:226

    const result = (deps.execFileSync || execFileSync)('ps', ['-p', pids.join(','), '-o', 'pid=,ppid=,rss=,etime=,stat='],
      { encoding: 'utf8', timeout: 2000, maxBuffer: 65536, shell: false, stdio: ['ignore','pipe','pipe'] });
    const processes = String(result).split('\n').filter(l => l.trim()).map(line => {
      const match = line.trim().match(/^(\d+)\s+(\d+)\s+(\d+)\s+([\d:-]+)\s+([A-Za-z+<>NsElLW]+)$/);
      if (!match) throw new Error('Invalid process metadata.');
      const values = match.slice(1,4).map(Number);
      if (values.some(v => !Number.isSafeInteger(v)) || !pids.includes(values[0])) throw new Error('Invalid process metadata.');
      return { pid: values[0], parentPid: values[1], rssBytes: values[2] * 1024, elapsed: match[4], flags: match[5] };
    });
    return { memory, processStatus: 'ok', processes };
  } catch { return { memory, processStatus: 'unavailable', processes: [] }; }
}

function readBounded(file, limit = MAX_BYTES) {
  // Refuse symlink final components, devices and files beyond the byte budget.
  const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
  try {
    const stat = fs.fstatSync(fd);
    if (!stat.isFile() || stat.size > limit) throw new Error('Input exceeds file limit.');
    const buffer = Buffer.alloc(limit + 1);
    let size = 0; let count;
    do { count = fs.readSync(fd, buffer, size, buffer.length - size, null); size += count; } while (count && size < buffer.length);
    if (size > limit) throw new Error('Input exceeds file limit.');
    return { content: buffer.subarray(0,size).toString('utf8'), modifiedAt: stat.mtime.toISOString() };
  } finally { fs.closeSync(fd); }
}
function readJson(file) {
  try { return JSON.parse(readBounded(file).content); }
  catch (error) { throw new Error(error.message === 'Input exceeds file limit.' ? error.message : 'Cannot read coordination JSON.'); }
}
function collectTaskFiles(directory) {
  try {
    const entries = fs.readdirSync(directory, { withFileTypes: true }).filter(e => e.isDirectory() && !e.name.startsWith('.')).sort((a,b) => a.name < b.name ? -1 : 1);
    if (entries.length > 64) throw new Error('Too many task directories.');
    const tasks = []; const unreadable = [];
    for (const entry of entries) {
      let loaded = false;

View on GitHub (pinned to 8321021c54)