fix(file): Truncate filenames with excessively long 'extensions'#12025
fix(file): Truncate filenames with excessively long 'extensions'#12025DEVELOPER-DEEVEN wants to merge 5 commits intoSignificant-Gravitas:devfrom
Conversation
|
This PR targets the Automatically setting the base branch to |
WalkthroughThe filename sanitization now preserves an extension only if its length is 20 characters or fewer; extensions longer than 20 characters are not preserved and the filename is truncated to MAX_FILENAME_LENGTH. A docstring wording tweak was made in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (4)autogpt_platform/backend/**/*.py📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
autogpt_platform/backend/**/*.{py,txt}📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)
Files:
autogpt_platform/backend/backend/**/*.py📄 CodeRabbit inference engine (autogpt_platform/backend/CLAUDE.md)
Files:
autogpt_platform/**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2026-02-04T16:50:20.508ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
🔇 Additional comments (2)
✏️ Tip: You can disable this entire section by setting Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| @@ -71,11 +71,15 @@ def sanitize_filename(filename: str) -> str: | |||
|
|
|||
| # Truncate if too long | |||
| if len(sanitized) > MAX_FILENAME_LENGTH: | |||
There was a problem hiding this comment.
Bug: The sanitize_filename() function checks filename length in characters, not bytes. This can cause an OSError for filenames with multi-byte characters that exceed filesystem byte limits.
Severity: HIGH
Suggested Fix
Modify the sanitize_filename() function to check the byte length of the filename after encoding it to UTF-8. The truncation logic should ensure that the final, encoded filename does not exceed the filesystem's byte limit (e.g., 255 bytes).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: autogpt_platform/backend/backend/util/file.py#L73
Potential issue: The `sanitize_filename()` function at line 73 validates filename length
by character count using `len()`, but most filesystems enforce a byte-limit (e.g., 255
bytes). A filename containing multi-byte UTF-8 characters (like emojis or CJK
characters) can pass the character-based check (e.g., < 200 characters) but still exceed
the filesystem's byte limit. This will cause an `OSError: [Errno 36] File name too long`
when the application attempts to write the file to disk in functions like
`store_media_file()`, leading to a crash of the operation.
Did we get this right? 👍 / 👎 to inform future reviews.
Fixes issue where filenames with no dots until the end (or massive extensions) bypassed truncation logic, causing OSError [Errno 36]. Limits extension preservation to 20 chars.