paperbot · PL 论文追踪

全部论文 待读 收藏

P2 On the Dual Nature of Necessity in Use of Rust Unsafe Code

论 Rust unsafe 代码使用中必要性的双重性质
FSE Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering2023匹配度 2/10 · 论文研究 Rust unsafe 代码的必要性及 IDE 插件建议安全替代,属于软件工程/程序分析,但未涉及 LLM/Agent、浮点程序分析或贝叶斯程序分析,与用户当前核心研究方向(AI 与 PL 交叉)不匹配。引用 17 inbox
Yuchen Zhang, Ashish Kundu, Georgios Portokalidis, Jun Xu
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:实证研究 Rust unsafe 代码的必要性,发现大量非必要使用,并设计 IDE 插件自动建议安全替代方案。

Rust 的 unsafe 块允许底层控制但放弃安全保证,原则上应仅在必要时使用,但已有迹象表明实际并非如此。本文对 140 个流行库和应用中的 5946 个 unsafe 块进行人工审查,判断其是否存在安全替代,从而评估使用的必要性。研究发现数百个不必要的 unsafe 实例,并给出分类体系与详细分析。基于此,作者总结九类常见的不必要 unsafe 模式,设计 IDE 插件自动推荐安全替代方案。将该插件应用于 RustSec Advisory Database 中 140 个有缺陷的 unsafe 块,在 28.6% 的案例中识别并提供可消除缺陷的安全版本。

问题
Rust unsafe 块提供底层控制却放弃安全保证,本文关注实践中 unsafe 的使用是否必要、是否存在安全替代。
方法
人工审查 140 个流行库和应用中的 5946 个 unsafe 块,归纳不必要使用的分类与九类常见模式,并实现自动建议安全替代的 IDE 插件。
评估
将插件应用于 RustSec Advisory Database 中 140 个有缺陷的 unsafe 块,在 28.6% 的案例中识别并提供可消除缺陷的安全版本。
原文摘要(Abstract)

Rust offers both safety guarantees and high performance. Thus, it has gained significant popularity in the industry. To extend its capability as a system programming language, Rust allows unsafe blocks where the execution has low-level controls but loses the safety guarantees. In principle, unsafe blocks should only be used when necessary. However, preliminary evidence shows a different situation. This paper aims to establish a deeper view of this matter and bring endeavors toward improvement. We first present a study on the use of unsafe Rust in practice. We manually inspected 5946 unsafe blocks from 140 popular libraries and applications, focusing on whether the use of unsafe code is necessary (precisely, whether they have safe alternatives). The study unveils hundreds of instances of unnecessary unsafe Rust code and provides a taxonomy together with detailed analyses. These results complement our understanding and offer insights for the community to make a change. Following the study, we further summarize nine popular patterns of unnecessary unsafe blocks and design an IDE plugin to auto-suggest their safe alternatives. Applied to 140 buggy unsafe blocks from the RustSec Advisory Database, the plugin identifies and offers safe versions to remove the bug for 28.6% of all cases.

链接与引用

DOI 原文 · PDF(开放获取) · DBLP

BibTeX
@inproceedings{ZhangKPX23,
  title = {On the Dual Nature of Necessity in Use of Rust Unsafe Code},
  author = {Yuchen Zhang and Ashish Kundu and Georgios Portokalidis and Jun Xu},
  booktitle = {FSE},
  year = {2023},
  doi = {10.1145/3611643.3613878}
}