No file-size limit when reading and tokenizing scanned files enables memory exhaustion
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 62/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust
- 领域
- performance, security
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Rust
- 星标
- 7.8k
- 派生
- 459
- 平均合并
- 3 天 20 小时
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mufeedvh/code2prompt 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
mufeedvh/code2prompt#355 ·
-
Symlink-to-file inside scanned root reads file content outside the root without --follow-symlinks未关闭
难度 2/5 1-3 小时 新手友好度 72/100
mufeedvh/code2prompt#354 ·
-
No tag 4.3.0未关闭
难度 1/5 1 小时以内 新手友好度 72/100
mufeedvh/code2prompt#340 · 1 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 66/100
mufeedvh/code2prompt#352 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 52/100
mufeedvh/code2prompt#345 ·
查看 mufeedvh/code2prompt 的全部 Issue
相似的 Issue
-
marketing
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
area:3d effort:medium P7 source:agent
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
enhancement ready-for-agent
难度 2/5 1-3 小时 新手友好度 65/100
publicusr/singularity#55 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 80/100
akitaonrails/ai-memory#2446 ·
维护者通常 1 天内回复