{"record":{"id":"0e5112aeedd199c9","repo":"alibaba/open-code-review","slug":"file-too-large-d-bytes-max-d","errorCode":null,"errorMessage":"file too large (%d bytes, max %d)","messagePattern":"file too large \\((.+?) bytes, max (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/config/rules/system_rules.go","lineNumber":656,"sourceCode":"\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\tif confineRoot != \"\" && !pathutil.WithinBase(confineRoot, resolved) {\n\t\treturn \"\", fmt.Errorf(\"rule file path %q escapes repo dir %q\", resolved, confineRoot)\n\t}\n\n\tif !allowedRuleExts[strings.ToLower(filepath.Ext(resolved))] {\n\t\treturn \"\", fmt.Errorf(\"unsupported extension %q, only .md/.txt/.markdown allowed\", filepath.Ext(resolved))\n\t}\n\n\tconst maxSize = 512 * 1024\n\tinfo, err := os.Stat(resolved)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif info.Size() > maxSize {\n\t\treturn \"\", fmt.Errorf(\"file too large (%d bytes, max %d)\", info.Size(), maxSize)\n\t}\n\n\tcontent, err := os.ReadFile(resolved)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn strings.TrimRight(string(content), \"\\n\"), nil\n}\n","sourceCodeStart":638,"sourceCodeEnd":666,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/config/rules/system_rules.go#L638-L666","documentation":"readRuleFileSafe size guard: a rule file (custom instructions loaded into the review prompt) exceeds 512 KiB. Oversized rule files would bloat prompts and slow or break LLM requests, so reading is refused with the actual and maximum sizes reported. The path must also be inside the repo and have an allowed extension, both checked before this.","triggerScenarios":"os.Stat on the resolved rule file reports a size > 524288 bytes; readRuleFileSafe returns before os.ReadFile.","commonSituations":"Pointing --rule at a huge generated doc, a concatenated changelog, or an entire documentation dump instead of a focused rules file; accidentally passing a data export (.md) with embedded base64 images.","solutions":["Split the rule file into smaller focused files and reference only the relevant one","Trim the rule file to the essential review guidelines (well under 512 KiB)","Generate a condensed summary of a large doc and use that as the rule file","Check which file is actually being passed — a wrong --rule target may be the oversized one"],"exampleFix":"// before\nocr review --rule ./docs/full-handbook.md   # 2 MB\n// after\nocr review --rule ./docs/review-guidelines.md   # 40 KB summary","handlingStrategy":"validation","validationCode":"func ensureRuleFileSize(p string, max int64) error {\n    fi, err := os.Stat(p)\n    if err != nil { return err }\n    if fi.Size() > max {\n        return fmt.Errorf(\"%s is %d bytes (max %d); trim or split it\", p, fi.Size(), max)\n    }\n    return nil\n}\n// ensureRuleFileSize(rulePath, 512*1024) before running ocr","typeGuard":null,"tryCatchPattern":"_, err := tryReadRuleFile(rulePath, confineRoot)\nif err != nil && strings.Contains(err.Error(), \"file too large\") {\n    fmt.Fprintln(os.Stderr, \"split the rule file into smaller focused .md files\")\n    os.Exit(2)\n}","preventionTips":["Keep rule files small and focused (<100 KB is plenty)","Never point --rule at generated docs or full handbooks; extract a summary","Add a size check to CI for the rule files you ship","Avoid embedding base64/binary blobs in rule markdown"],"tags":["go","config","file-size","limits"],"backgroundTag":"file-too-large","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}