Skip to content

Commit 920f8b9

Browse files
YedPoolclaude
andcommitted
Fix memory issue: only read file contents for small suspicious files
Prevent reading 39MB binary into memory and logging it 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8c16d41 commit 920f8b9

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

livekit-server/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,14 @@ def start(self):
174174
result = subprocess.run(['file', binary_path], capture_output=True, text=True)
175175
logger.info(f" File type: {result.stdout.strip()}")
176176

177-
# Show file contents since it's only 9 bytes
178-
with open(binary_path, 'rb') as f:
179-
content = f.read()
180-
logger.info(f" File contents (hex): {content.hex()}")
181-
logger.info(f" File contents (text): {content.decode('utf-8', errors='ignore')}")
177+
# Only show file contents if it's suspiciously small (likely an error)
178+
if stat_info.st_size < 1000:
179+
with open(binary_path, 'rb') as f:
180+
content = f.read()
181+
logger.info(f" File contents (hex): {content.hex()}")
182+
logger.info(f" File contents (text): {content.decode('utf-8', errors='ignore')}")
183+
else:
184+
logger.info(f" Binary appears valid (size: {stat_info.st_size} bytes)")
182185
except Exception as e:
183186
logger.info(f" Could not analyze file: {e}")
184187

0 commit comments

Comments
 (0)