{"record":{"id":"1983b69a281b5682","repo":"Panniantong/Agent-Reach","slug":"target-1983b6","errorCode":null,"errorMessage":"读取目标超过大小上限：{target}","messagePattern":"读取目标超过大小上限：(.+?)","errorType":"exception","errorClass":"PrivatePathError","httpStatus":null,"severity":"error","filePath":"agent_reach/utils/paths.py","lineNumber":166,"sourceCode":"\n    target = ensure_no_symlink_path(path, \"读取路径\")\n    flags = (\n        os.O_RDONLY\n        | getattr(os, \"O_NOFOLLOW\", 0)\n        | getattr(os, \"O_NONBLOCK\", 0)\n        | getattr(os, \"O_CLOEXEC\", 0)\n    )\n    try:\n        fd = os.open(target, flags)\n    except FileNotFoundError:\n        return None\n\n    try:\n        file_stat = os.fstat(fd)\n        if not stat.S_ISREG(file_stat.st_mode):\n            raise PrivatePathError(f\"读取目标不是常规文件：{target}\")\n        if file_stat.st_size > max_bytes:\n            raise PrivatePathError(f\"读取目标超过大小上限：{target}\")\n\n        chunks = []\n        remaining = max_bytes + 1\n        while remaining:\n            chunk = os.read(fd, remaining)\n            if not chunk:\n                break\n            chunks.append(chunk)\n            remaining -= len(chunk)\n        payload = b\"\".join(chunks)\n        if len(payload) > max_bytes:\n            raise PrivatePathError(f\"读取目标超过大小上限：{target}\")\n        ensure_no_symlink_path(target, \"读取路径\")\n    finally:\n        os.close(fd)\n    return payload.decode(encoding)\n\n","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/Panniantong/Agent-Reach/blob/93ae1d18c37b707dec053c7c4f9d91cd8ef8943d/agent_reach/utils/paths.py#L148-L184","documentation":"First of two size-cap checks in the private file reader: after opening the fd, fstat reports st_size greater than max_bytes and the read is refused before any I/O. Message (Chinese): 'read target exceeds size limit: {target}'. It protects fixed-size readers (config/token files) from being fed huge files.","triggerScenarios":"Calling the private read helper (the max_bytes function) with a target whose on-disk size already exceeds max_bytes — e.g. reading a multi-MiB export into a helper sized for a small token file.","commonSituations":"Cookie export files or logs grown far larger than expected; accidentally pointing at a media file; max_bytes left at a default meant for small secrets.","solutions":["Check the actual file: ls -lh <target> — decide whether it is the right file","Pass a max_bytes appropriate for the content you expect, if you are the caller choosing the cap","If the file is legitimately huge, stream it with your own reader instead of this capped helper"],"exampleFix":"# before\ndata = read_private_file(cookie_export, max_bytes=1024)  # file is 2 MiB\n\n# after\ndata = read_private_file(cookie_export, max_bytes=8 * 1024 * 1024)","handlingStrategy":"validation","validationCode":"import os\n\ndef size_within(target: str, max_bytes: int) -> bool:\n    try:\n        return os.stat(target).st_size <= max_bytes\n    except OSError:\n        return False","typeGuard":null,"tryCatchPattern":"from agent_reach.utils.paths import PrivatePathError\ntry:\n    data = read_private(target, max_bytes=cap)\nexcept PrivatePathError as e:\n    if \"大小上限\" in str(e):\n        real = os.path.getsize(target)\n        if real > _HARD_MAX:\n            raise ValueError(f\"{target} is unexpectedly {real} bytes\")\n        data = read_private(target, max_bytes=_HARD_MAX)\n    else:\n        raise","preventionTips":["Pick max_bytes from the real format budget (e.g. 1 MiB for YAML configs, more for cookie exports)","Stat expected files in smoke tests so silent growth is caught early","Never point capped secret readers at unbounded files like logs or media"],"tags":["filesystem","limits","validation","security"],"backgroundTag":null,"analyzedSha":"93ae1d18c37b707dec053c7c4f9d91cd8ef8943d","analyzedAt":"2026-08-14T22:54:06.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}