Repository navigation
fix(tools): cap total size and file count when reading directories from the sandbox - #469
Open
Dextheking1 wants to merge 1 commit into
Open
Dextheking1 wants to merge 1 commit into
Dextheking1 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
readFileFromContainer in backend/pkg/tools/terminal.go caps each single file at 100 MB, but when the path is a directory it appends every file to one in-memory buffer with no total size limit and no limit on the number of files. A directory holding a few hundred files just under the per-file cap grows the backend's memory until the process dies. EditFile reads through the same function, so an edit on such a directory hits it too.
The content of a flow's container is agent-controlled, and the backend is the process holding the Docker socket and the provider keys, so this takes down every flow, not just the one that caused it.
Solution
Count the entries and the total declared size while reading. Refuse the read past 1000 files, or past the same 100 MB in total, with errors in the existing style. Single file reads behave exactly as before, including the existing per-file error message.
Type of change
Areas affected
Testing
Test cases
Verification steps
Security considerations
Checklist
Additional notes
The limits reuse the existing 100 MB figure so a directory read and a single file read now share one budget. The files in a flow's work directory are listed and read as a set elsewhere too, so 1000 entries leaves plenty of room for normal work.