mirror of
https://github.com/open-webui/open-terminal.git
synced 2026-11-05 01:27:28 +00:00
[PR #144] fix: prevent context overflow from extremely long lines in grep_search #137
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/open-terminal#137
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-terminal/pull/144
Author: @Delta062
Created: 7/29/2026
Status: 🔄 Open
Base:
main← Head:fix/grep-search-context-overflow📝 Commits (1)
45bb44cfix: prevent context overflow from extremely long lines in grep_search📊 Changes
1 file changed (+18 additions, -1 deletions)
View changed files
📝
open_terminal/main.py(+18 -1)📄 Description
Fix: Prevent context overflow from extremely long lines in grep_search
Problem
The
grep_searchendpoint returns the full content of matched lines with no length protection. When searching directories containing files with embedded binary blobs (e.g., base64-encoded payloads in shell scripts), a single match can return over 1 megabyte of content.Real-world impact
A reported incident on 2026-07-29 showed:
grep_searchcall scoped to a home directory returned 1,144,419 characters in a single responseinstall-club3090-server.shThis is particularly problematic for AI agent integrations (like Open WebUI MCP tools) where tool responses are injected directly into the model context window.
Solution
Two defensive caps added to the
_search_filefunction:Skip absurdly long lines (
_MAX_LINE_LENGTH = 2000): Lines exceeding 2000 characters are almost certainly embedded binary blobs (base64, wheels, minified assets), not real source code. Skip them entirely.Cap returned content per match (
_MAX_MATCH_CONTENT = 300): Even for legitimate long lines, truncate the returned content to 300 characters with a truncation notice. This preserves the match location (file + line number) while preventing context overflow.Why these values?
max_resultsupper bound) stays under 150K total charactersBehavior change
... [truncated, full line was N chars]This is non-breaking for normal usage — typical source files are unaffected. The protection only activates for edge cases that were already causing failures.
Testing
Verified against the original failing query:
Alternative Considered
Making these values configurable via environment variables (
OPEN_TERMINAL_MAX_LINE_LENGTH,OPEN_TERMINAL_MAX_MATCH_CONTENT) is possible but adds complexity for what should be sensible defaults. The current hardcoded values are defensive enough that configuration is not needed for the vast majority of users.If maintainers prefer configurability, I am happy to refactor — but the core safety logic should remain.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.