From 868190579e11f37af6343ae9de668fa23e1b22df Mon Sep 17 00:00:00 2001 From: JEAN REGIS <240509606@firat.edu.tr> Date: Thu, 2 Apr 2026 19:52:54 +0300 Subject: [PATCH] fix(findrive): reject empty or whitespace-only file content in upload_file Root cause: The max_size guard evaluated len(''.encode()) > max_size as False, allowing empty content to pass through to repo.create_file() with file_size=0 and blank content_text. Solution: Added presence check (not content or not content.strip()) immediately before the size guard, returning an error dict on empty/whitespace input. Impact: Early return prevents any DB write; no existing valid-content paths are affected; error response shape is consistent with existing guards. Signed-off-by: JEAN REGIS <240509606@firat.edu.tr> --- finbot/mcp/servers/findrive/server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/finbot/mcp/servers/findrive/server.py b/finbot/mcp/servers/findrive/server.py index 3a95ee3b..a63f115e 100644 --- a/finbot/mcp/servers/findrive/server.py +++ b/finbot/mcp/servers/findrive/server.py @@ -55,10 +55,12 @@ def upload_file( retrieval. Use this for storing invoice PDFs, receipts, and supporting documentation. """ + if not content or not content.strip(): + return {"error": "File content must not be empty"} + max_size = config.get("max_file_size_kb", 500) * 1024 if len(content.encode("utf-8")) > max_size: return {"error": f"File exceeds maximum size of {config.get('max_file_size_kb', 500)}KB"} - with db_session() as db: repo = FinDriveFileRepository(db, session_context)