Skip to content

Commit c2fed2e

Browse files
author
Akkari
committed
fix: check file size before reading into memory (prescreen)
Quorum CI finding #8: stat() before read_text() to prevent memory exhaustion on oversized files. The len() check after read was too late.
1 parent a38b6c2 commit c2fed2e

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

ports/copilot-cli/quorum-prescreen.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,26 @@ def run_prescreen(target_path: Path) -> dict:
545545
print(f"Error: file not found: {target_path}", file=sys.stderr)
546546
sys.exit(1)
547547

548+
# ── Input validation (size check before read to prevent memory exhaustion) ─
549+
file_size = target_path.stat().st_size
550+
if file_size > MAX_ARTIFACT_SIZE:
551+
print(
552+
f"Error: artifact too large ({file_size} bytes), max {MAX_ARTIFACT_SIZE}",
553+
file=sys.stderr,
554+
)
555+
return {
556+
"target": str(target_path),
557+
"total_checks": 0,
558+
"passed": 0,
559+
"failed": 0,
560+
"skipped": 0,
561+
"checks": [],
562+
}
563+
548564
artifact_text = target_path.read_text(encoding="utf-8", errors="replace")
549565
ext = target_path.suffix.lower()
550566
checks: list[dict] = []
551567

552-
# ── Input validation ──────────────────────────────────────────────────
553568
if len(artifact_text) > MAX_ARTIFACT_SIZE:
554569
print(
555570
f"Error: artifact too large ({len(artifact_text)} bytes), max {MAX_ARTIFACT_SIZE}",

0 commit comments

Comments
 (0)