mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-12 15:55:03 -05:00
fix: skip binary file if stat fails to prevent OOM
If the stat command fails (file deleted, permissions issue, etc.), we now skip the file rather than proceeding to read it with an unknown size. This prevents potential OOM crashes from large files where size verification failed.
This commit is contained in:
@@ -666,15 +666,23 @@ class ClaudeCodeBlock(Block):
|
||||
stat_result = await sandbox.commands.run(
|
||||
f"stat -c %s {shlex.quote(file_path)} 2>/dev/null"
|
||||
)
|
||||
if stat_result.stdout:
|
||||
file_size = int(stat_result.stdout.strip())
|
||||
if file_size > MAX_BINARY_FILE_SIZE:
|
||||
logger.warning(
|
||||
f"Skipping binary file {file_path}: "
|
||||
f"size {file_size} exceeds limit "
|
||||
f"{MAX_BINARY_FILE_SIZE}"
|
||||
)
|
||||
continue
|
||||
if (
|
||||
stat_result.exit_code != 0
|
||||
or not stat_result.stdout
|
||||
):
|
||||
logger.warning(
|
||||
f"Skipping binary file {file_path}: "
|
||||
f"could not determine file size"
|
||||
)
|
||||
continue
|
||||
file_size = int(stat_result.stdout.strip())
|
||||
if file_size > MAX_BINARY_FILE_SIZE:
|
||||
logger.warning(
|
||||
f"Skipping binary file {file_path}: "
|
||||
f"size {file_size} exceeds limit "
|
||||
f"{MAX_BINARY_FILE_SIZE}"
|
||||
)
|
||||
continue
|
||||
|
||||
# Read binary file as bytes using format="bytes"
|
||||
content_bytes = await sandbox.files.read(
|
||||
|
||||
Reference in New Issue
Block a user