{"record":{"id":"c775e15b95d43e51","repo":"abhigyanpatwari/GitNexus","slug":"filename-exceeds-max-repo-control-file-bytes","errorCode":null,"errorMessage":"${filename} exceeds ${MAX_REPO_CONTROL_FILE_BYTES} bytes","messagePattern":"(.+?) exceeds (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/config/repo-control-file.ts","lineNumber":25,"sourceCode":"export async function readRepoControlFile(\n  repoRoot: string,\n  filename: string,\n): Promise<string | null> {\n  const requestedRoot = path.resolve(repoRoot);\n  const requested = path.resolve(requestedRoot, filename);\n  const relative = path.relative(requestedRoot, requested);\n  if (relative.startsWith('..') || path.isAbsolute(relative)) {\n    throw new Error(`${filename} resolves outside the repository root`);\n  }\n\n  try {\n    const canonicalRoot = fs.realpathSync(requestedRoot);\n    const beforeOpen = fs.lstatSync(requested);\n    if (beforeOpen.isSymbolicLink()) throw new Error(`${filename} must not be a symbolic link`);\n    if (!beforeOpen.isFile()) throw new Error(`${filename} must be a regular file`);\n    if (beforeOpen.nlink !== 1) throw new Error(`${filename} must not be a hard link`);\n    if (beforeOpen.size > MAX_REPO_CONTROL_FILE_BYTES) {\n      throw new Error(`${filename} exceeds ${MAX_REPO_CONTROL_FILE_BYTES} bytes`);\n    }\n    return await new Promise<string>((resolve, reject) => {\n      const stream = fs.createReadStream(requested, {\n        flags: 'r',\n        start: 0,\n        end: MAX_REPO_CONTROL_FILE_BYTES,\n        autoClose: true,\n      });\n      const chunks: Buffer[] = [];\n      let totalBytes = 0;\n      let validated = false;\n      let settled = false;\n\n      const finish = (value: string): void => {\n        if (settled) return;\n        settled = true;\n        resolve(value);\n      };","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/52924ef12c2290ceee4612526a828ec4cdf2047f/gitnexus/src/config/repo-control-file.ts#L7-L43","documentation":"readRepoControlFile enforces a maximum size (MAX_REPO_CONTROL_FILE_BYTES) on control files both before and during reading; the pre-open lstat check throws this error when the file is already too large. This prevents pathological memory/DoS exposure from an oversized or maliciously grown config file.","triggerScenarios":"Calling readRepoControlFile when fs.lstatSync(requested).size exceeds MAX_REPO_CONTROL_FILE_BYTES — i.e. the control file on disk is larger than the configured byte cap.","commonSituations":"A log or output file was accidentally redirected into the config path; a generated config ballooned after a bad script concatenated repeatedly; someone replaced the config with a large binary blob.","solutions":["Inspect `fs.lstatSync(path).size` and compare against MAX_REPO_CONTROL_FILE_BYTES; trim the file to the allowed size.","Remove accidental content (logs, duplicates) from the control file, keeping only the intended config.","Restore the file from version control (`git checkout -- <file>`).","Regenerate the control file with the tooling that originally created it."],"exampleFix":"// before: oversized .gitnexusrc (e.g. 10 MB of appended logs)\ncat debug.log >> .gitnexusrc\n// after: small, hand-maintained file\nprintf 'mode: strict\\n' > .gitnexusrc","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nconst st = fs.lstatSync(controlFilePath);\nconst MAX = 64 * 1024; // match MAX_REPO_CONTROL_FILE_BYTES\nif (st.size > MAX) {\n  throw new Error(`${controlFilePath} is ${st.size} bytes; cap is ${MAX}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await readRepoControlFile(root, filename);\n} catch (err) {\n  if ((err as Error).message.includes('exceeds') && err.message.includes('bytes')) {\n    // trim or regenerate the config below the cap, then retry\n  } else throw err;\n}","preventionTips":["Never redirect logs or command output into the control file.","Keep generated configs minimal; review file size after generation.","Restore oversized files from version control instead of hand-trimming."],"tags":["filesystem","validation","size-limit","config"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"52924ef12c2290ceee4612526a828ec4cdf2047f","analyzedAt":"2026-09-01T13:15:02.810Z","contentChangedAt":"2026-09-01T13:15:02.810Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}