No file-size limit when reading and tokenizing scanned files enables memory exhaustion
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 62/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust
- Lĩnh vực
- performance, security
Hướng nghiên cứu
Start at read_file_with_binary_check, where file.read_to_end fills an unbounded buffer, then follow that buffer through encoding detection and tiktoken tokenization to see where the memory amplification happens. Check the file-walking and configuration code for an existing size or ignore mechanism that a cap could reuse, since the fix needs a defined behavior for oversized files (skip, truncate, or error). Reproduce with a 32 MiB text file as described and measure peak RSS; done means scanning such a file stays bounded and there is a test covering the oversized-file case.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Denial of service in code2prompt: read_file_with_binary_check uses file.read_to_end(&mut buffer) with no upper bound; the Vec::with_capacity(file_size.min(10MB)) is only an initial-allocation hint. The full buffer is then passed through encoding detection and tiktoken tokenization with no size limit.
To reproduce
Create a large text file in a scanned root and run 'code2prompt -q -O /dev/null '; observe peak RSS far exceeding the input size.
Expected
Attacker-influenced file sizes should be bounded so a scanned codebase cannot exhaust memory.
Actual
32 MiB input consumed ~1.7 GiB peak RSS
Independent CLI reproduction with a 32 MiB text file measured ~1.7 GiB peak RSS (32 MiB input -> ~54x memory amplification), confirming unbounded buffering and tokenization with no effective size cap in read_file_with_binary_check (file.read_to_end with no upper bound). A full OOM was not induced to avoid destabilizing the environment.
Observed side effect:
Command being timed: "/tmp/c2p-build/target/debug/code2prompt -q -O /dev/null /tmp/v4-big-1795224600"
User time (seconds): 134.91
System time (seconds): 1.34
Percent of CPU this job got: 100%
Elapsed (wall clock) time (h:mm:ss or m:ss): 2:16.02
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1724416
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 496785
Voluntary context switches: 1767
Involuntary context switches: 501
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Impact
Local denial of service via memory exhaustion when scanning an attacker-influenced large file.
Version
v4.2.0
- Ngôn ngữ chính
- Rust
- Star
- 7.8k
- Fork
- 459
- Merge trung bình
- 3 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mufeedvh/code2prompt
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
mufeedvh/code2prompt#355 ·
-
Symlink-to-file inside scanned root reads file content outside the root without --follow-symlinksĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mufeedvh/code2prompt#354 ·
-
No tag 4.3.0Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
mufeedvh/code2prompt#340 · 1 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
mufeedvh/code2prompt#352 · 1 bình luận ·
-
Vim navigation featureĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
mufeedvh/code2prompt#345 ·
Tất cả issue của mufeedvh/code2prompt
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
topgrade-rs/topgrade#2540 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Invalid JSON options for ngram and edge_ngram silently use defaultsCó thể đã có người làm @Tilendlesa đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
noemaforge/vimanam#153 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày