返回资讯中心
外部精选
软件工程
#开发者实时流

Rustc silently substitutes file contents when path hashes collide

`rustc` uses the `Path` hash code to identify files, and the `Path` hash implementation is particularly weak because it ignores separators. As of PR #127297, it tries to compensate by mixing the component lengths into t…

Hacker News 最新acossta2026/10/15 · 2026/10/154 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

rustc uses the Path hash code to identify files, and the Path hash implementation is particularly weak because it ignores separators. As of PR #127297, it tries to compensate by mixing the component lengths into the hash, but it's still easy to manufacture collisions. That includes collisions where both sides look like plausible source paths, not gibberish, e.g. data/baselines/table.rs will conflict with database/line/stable.rs.

When the hash codes of two paths collide, rustc substitutes the first file's contents when compiling the second one. See the attached repro scripts.

repro-plain.sh

repro-quiet.sh

This sounds totally frivolous at first, you'd just get a very confusing errors for any accidental collisions/substitutions, but it does technically allow for review evasion / hiding backdoors. Most audit tooling would not re-implement the same bug the same way, and no reviewer would ever think to look for file content substitution. (The two conflicting files could added in separate commits to avoid suspicion).

The difference between the two repros is that the plain version is noisy for some very common workflows. E.g. it'd also cause cargo fmt to replace one file's contents with the other's. The quiet version avoids that.

Proposed fix:

Meta

Tested on 1.99.0 and nightly-2026-10-11.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →