fix: add file size validation to prevent memory exhaustion#6157
Closed
roomote[bot] wants to merge 1 commit intomainfrom
Closed
fix: add file size validation to prevent memory exhaustion#6157roomote[bot] wants to merge 1 commit intomainfrom
roomote[bot] wants to merge 1 commit intomainfrom
Conversation
- Add MAX_FILE_SIZE_BYTES constants for different file types - Add size validation to readFileIfExists() in roo-config service - Add size validation to .gitignore reading in list-files service - Add size validation to checkpoint file reading in ShadowCheckpointService - Add size validation to MCP config reading in McpHub - Add comprehensive tests for file size validation - Add FileSizeLimitError class for better error handling This prevents memory exhaustion and performance issues when reading large files across various Roo-Code services. Fixes #6155
026fb4d to
40a52ae
Compare
6 tasks
Member
|
Closing in favor of #6174 |
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.
Summary
This PR implements file size validation across all file reading operations in Roo-Code to prevent memory exhaustion and performance issues, as identified in #6155.
Changes
1. Created shared file size constants (
src/services/constants/file-limits.ts)MAX_FILE_SIZE_BYTES: 1MB for general filesMAX_CONFIG_FILE_SIZE_BYTES: 100KB for configuration filesMAX_GITIGNORE_FILE_SIZE_BYTES: 50KB for .gitignore filesMAX_CHECKPOINT_FILE_SIZE_BYTES: 5MB for checkpoint filesformatBytes()helper andFileSizeLimitErrorclass2. Added file size validation to:
readFileIfExists()now checks file size before reading3. Added comprehensive unit tests
fs.stat()callsTesting
Notes
nullor skip the file rather than throwing errors, maintaining backward compatibilityFixes #6155
Important
Add file size validation to prevent memory exhaustion by setting limits for different file types and updating services to enforce these limits.
nullor skip files exceeding size limits to maintain backward compatibility.MAX_FILE_SIZE_BYTES,MAX_CONFIG_FILE_SIZE_BYTES,MAX_GITIGNORE_FILE_SIZE_BYTES,MAX_CHECKPOINT_FILE_SIZE_BYTESinfile-limits.ts.FileSizeLimitErrorclass for handling size violations.readFileIfExists()inroo-configto check file size.list-filesfor.gitignorefiles.ShadowCheckpointService.McpHub.list-files-gitignore-size.spec.tsandindex.spec.ts.fs.stat()in tests to simulate file size scenarios.This description was created by
for 40a52ae. You can customize this summary. It will automatically update as commits are pushed.