{"record":{"id":"2ce39758691ceaf0","repo":"ipfs/kubo","slug":"api-file-too-large-must-be-2048-bytes-long-s","errorCode":null,"errorMessage":"API file too large, must be <2048 bytes long: %s","messagePattern":"API file too large, must be <2048 bytes long: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/fsrepo.go","lineNumber":370,"sourceCode":"\t\t}\n\t\treturn nil, err\n\t}\n\tdefer f.Close()\n\n\t// read up to 2048 bytes. io.ReadAll is a vulnerability, as\n\t// someone could hose the process by putting a massive file there.\n\t//\n\t// NOTE(@stebalien): @jbenet probably wasn't thinking straight when he\n\t// wrote that comment but I'm leaving the limit here in case there was\n\t// some hidden wisdom. However, I'm fixing it such that:\n\t// 1. We don't read too little.\n\t// 2. We don't truncate and succeed.\n\tbuf, err := io.ReadAll(io.LimitReader(f, 2048))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(buf) == 2048 {\n\t\treturn nil, fmt.Errorf(\"API file too large, must be <2048 bytes long: %s\", apiFilePath)\n\t}\n\n\ts := string(buf)\n\ts = strings.TrimSpace(s)\n\treturn ma.NewMultiaddr(s)\n}\n\nfunc (r *FSRepo) Keystore() keystore.Keystore {\n\treturn r.keystore\n}\n\nfunc (r *FSRepo) Path() string {\n\treturn r.path\n}\n\n// SetAPIAddr writes the API Addr to the /api file.\nfunc (r *FSRepo) SetAPIAddr(addr ma.Multiaddr) error {\n\t// Create a temp file to write the address, so that we don't leave empty file when the","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/fsrepo.go#L352-L388","documentation":"Reading $IPFS_PATH/api (the file tracking the daemon's RPC address) hit the deliberate 2048-byte cap: the file is read through a LimitReader as a safety measure, and reaching exactly 2048 bytes means it is not a sane API file (corrupted or planted).","triggerScenarios":"Thrown at repo/fsrepo/fsrepo.go:370 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Delete the stale 'api' file in the repo directory and restart (or let the daemon rewrite it)","Check nothing is writing garbage into $IPFS_PATH/api","Re-run with a fresh IPFS_PATH if the repo is untrusted"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}