{"record":{"id":"cdec94a8cd1f12fe","repo":"crewAIInc/crewAI","slug":"file-exceeds-max-size-actual-size-self-max-s","errorCode":null,"errorMessage":"File exceeds max size ({actual_size} > {self.max_size_bytes})","messagePattern":"File exceeds max size \\((.+?) > (.+?)\\)","errorType":"exception","errorClass":"FileTooLargeError","httpStatus":null,"severity":"warning","filePath":"lib/crewai-files/src/crewai_files/core/sources.py","lineNumber":240,"sourceCode":"\n        path_str = str(self.path)\n        if \"..\" in path_str:\n            raise ValueError(f\"Path traversal not allowed: {self.path}\")\n\n        if self.path.is_symlink():\n            resolved = self.path.resolve()\n            cwd = Path.cwd().resolve()\n            if not str(resolved).startswith(str(cwd)):\n                raise ValueError(f\"Symlink escapes allowed directory: {self.path}\")\n\n        if not self.path.exists():\n            raise ValueError(f\"File not found: {self.path}\")\n        if not self.path.is_file():\n            raise ValueError(f\"Path is not a file: {self.path}\")\n\n        actual_size = self.path.stat().st_size\n        if actual_size > self.max_size_bytes:\n            raise FileTooLargeError(\n                f\"File exceeds max size ({actual_size} > {self.max_size_bytes})\",\n                file_name=str(self.path),\n                actual_size=actual_size,\n                max_size=self.max_size_bytes,\n            )\n\n        self._content_type = detect_content_type_from_path(self.path, self.path.name)\n        return self\n\n    @property\n    def filename(self) -> str:\n        \"\"\"Get the filename from the path.\"\"\"\n        return self.path.name\n\n    @property\n    def content_type(self) -> str:\n        \"\"\"Get the content type.\"\"\"\n        return self._content_type","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-files/src/crewai_files/core/sources.py#L222-L258","documentation":"Raised as FileTooLargeError (a dedicated exception, not ValueError) from FilePath's validator when stat().st_size exceeds max_size_bytes (default DEFAULT_MAX_FILE_SIZE_BYTES, field is settable). This guard prevents loading huge files into memory. Because it is a different exception class, a bare ValueError catch will miss it.","triggerScenarios":"FilePath(path=big_video, max_size_bytes=10_000_000) where the file is 50 MB; leaving the default cap while processing large media; logs or data dumps exceeding the configured limit.","commonSituations":"Accepting user uploads of arbitrary size; feeding model-context pipelines where a size cap protects the LLM context; PDFs/videos commonly exceed small defaults.","solutions":["Raise the limit explicitly if your use case allows: FilePath(path=p, max_size_bytes=100_000_000).","Pre-check size before constructing: p.stat().st_size <= limit.","Catch crewai_files.processing.exceptions.FileTooLargeError specifically and reject/downsample the file.","Split or compress oversized files upstream instead of loading them whole."],"exampleFix":"# before\nsrc = FilePath(path=video_path)  # FileTooLargeError with default cap\n\n# after\nsrc = FilePath(path=video_path, max_size_bytes=500_000_000)","handlingStrategy":"try-catch","validationCode":"from pathlib import Path\n\ndef size_ok(p: Path, limit: int) -> bool:\n    return p.stat().st_size <= limit","typeGuard":null,"tryCatchPattern":"from crewai_files.processing.exceptions import FileTooLargeError\ntry:\n    src = FilePath(path=p)\nexcept FileTooLargeError as e:\n    print(f\"reject {e.file_name}: {e.actual_size} > {e.max_size}\")  # 413-style response in a web app","preventionTips":["Check Content-Length / stat().st_size before accepting or loading files.","Catch FileTooLargeError specifically — it is not a ValueError subclass path in the validator.","Expose max_size_bytes in user-facing config so limits are tunable."],"tags":["validation","file-size","file-sources","limits"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}