编程语言与软件工程2017spw17.langsec.org
像 2017 年那样编写解析器
Writing Parsers Like it is 2017
进阶 · 约 60 分钟读完前置知识:Rust 基础、解析器组合子概念、C 语言与内存安全
导读
这篇论文讨论如何用 Rust 的解析器组合子库 nom 重写那些用 C 写的、易受内存破坏攻击的解析器,并以 VLC 和某入侵检测系统为案例,讲述把新解析器集成进既有复杂 C 代码库、用 fuzzing 验证的过程。作者还总结了 C 解析器常见的安全陷阱,以及为提升安全性对 Rust 提出的一些改进建议。
HN 关注点:HN 读者既认可"用 Rust 重写危险 C 解析器"的实证案例,也质疑论文开头用缺乏数据支撑的论断为 Rust 全面背书。
HN 评论精选
这几条评论里:支持 1 质疑 1 补充 2
质疑肯定案例价值,但批评论文用无数据支撑的论断为 Rust 站台。
这篇论文的标题可以更诚实一点,比如叫《用 nom 快速以 Rust 替换危险 C 解析器代码的案例研究》。文中的示例有趣、呈现得也好,但前几节试图给"一切都该用 Rust 重写"镀上一层体面的外衣,读起来有点勉强,让我这个怀疑论者警觉。是的,你相信 Rust 会带来更好的结果,但别用你并没有的事实去论证——那句"测试了若干种语言……"纯属胡扯,除非你拿出数据;关于类型安全和无 GC 是必要属性的断言同理。你真正拥有的数据(在论文级别的时间框架内完成实现、集成并测试)是有价值的,可惜被这层虚假的外衣廉价化、掩埋了。
saywatnow查看英文原文
This should be titled more honestly: perhaps something like "Case studies in rapidly replacing dangerous C parser code with Rust using nom". The examples are interesting and well presented. But the first sections trying to put a veneer of respectability on rust-all-the-things were a bit rough and got my cynic sense tingling. Yes, you believe Rust will produce better results: don't try to justify that with facts you don't have ("Several languages were tested .." bullshit, unless you show some data. Likewise the assertions about type-safety and no-GC being essential properties). The data you do have (implementations produced and integrated and tested in a paper-like time frame) are valuable, unfortunately they're cheapened/buried under this false veneer.
补充提出疑问:为何缺少既好用(错误信息友好)又可形式化验证的解析器生成器。
有没有可能做出能生成递归下降解析器的"解析器生成器"(不必是形式化意义上的)?即便理论上做不到完美,能不能有"够用"的版本?没人用解析器生成器,是因为它们虽然勉强能把源码读进去、吐出 AST,但仅此而已。比如想从生成器的输出里得到有用的错误信息(想想老 GCC 到 Clang 的进步)几乎不可能。于是大家都手写解析器,也就带来了这些问题。我们能不能有更聪明的生成器,既让调试体验好,又能保持形式化验证?
Analemma_查看英文原文
Is it possible to have "parser generators" (not necessarily in the formal sense of the term) that produce recursive descent parsers? Even if mathematically they can't be perfect, could we have "good enough" ones? Nobody uses parser generators because even though P.G.s "work" on the barest level of ingesting source code and spitting an AST, they don't do anything beyond that. For example, trying to get helpful error messages (think: from old GCC to Clang) from a P.G.s output is close So instead everyone writes custom parsers, and that introduces these problems. Can't we have smarter parser generators that do make debugging nice, but are still formally verified?
支持概括全文脉络:C 解析器陷阱、nom、VLC 与 IDS 案例、fuzzing。
很好的综述:C 解析器的坑、加固手段、Rust 的优势、解析器组合子、nom crate 及其用法、在 VLC 和入侵检测器上的应用、与那些复杂既有 C 代码库的集成、fuzzing,以及一些为提升安全性改进 Rust 的想法。另外很高兴看到 ANSSI 出现在这里 :)
BigIQ查看英文原文
Nice overview of the pitfalls of C-parsers, their hardening, a presentation of Rust advantages, parser combinators, the nom crate, its usage, the application to VLC and an intrusion detector, the integration with those complex existing C codebase, fuzzing and a few ideas to improve rust for more security. And I am happy to see the ANSSI here :)
补充调侃解析理论早已成熟,写解析器没什么新东西。
只要还在写解析器,就永远停留在 1969 年。Knuth 不久前才把该知道的一切都发明完了。放手去解析吧!
kazinator查看英文原文
As long as you're writing parsers, it is forever 1969. Knuth invented all you need to know just recently. Off you go and parse!
相关资源
从这篇论文所有 HN 讨论帖的全部评论里整理出来的链接。
历次讨论
- 2017Hacker News 讨论帖205 分 · 49 评
同领域还值得读
Google 的软件工程(2017)
Software Engineering at Google (2017)
介绍了 Google 的软件工程实践,包括其单一代码库(monorepo)、几乎全部开发在主干进行而非分支、代码审查、构建系统 Blaze、协议缓冲区等工具与流程,并讨论了频繁重…
编程语言与软件工程2017 · 1,127 分 · 465 评 · 引用 15入门 · 约 45 分钟编辑精选Peter Naur:编程作为理论构建 (1985)
Peter Naur – Programming as Theory Building (1985)
Peter Naur 1985 年的经典论文《Programming as Theory Building》提出:编程的本质不是写代码或文档,而是在程序员头脑中构建对程序及其运行…
编程语言与软件工程2016 · 629 分 · 74 评入门 · 约 45 分钟编辑精选SciPy 1.0:Python 科学计算的基础算法
SciPy 1.0: fundamental algorithms for scientific computing in Python
这篇发表于 Nature Methods 的论文介绍了 SciPy 1.0——Python 科学计算生态的基石库,涵盖其核心算法模块(优化、积分、插值、线性代数等)、软件架构与社…
编程语言与软件工程2020 · 387 分 · 98 评入门 · 约 45 分钟编辑精选Lisp 的历史(1979)
History of Lisp (1979)
这是 Lisp 发明者 John McCarthy 于 1979 年为 HOPL(编程语言史)会议撰写的回顾文章,讲述 Lisp 的起源、设计动机与早期演进,文中也涉及 if 表…
编程语言与软件工程2018 · 352 分 · 44 评入门 · 约 45 分钟编辑精选使用 NumPy 进行数组编程
Array Programming with NumPy
这篇 Nature 文章介绍 NumPy 的数组编程模型及其在科学计算中的核心作用:以 ndarray 为中心,通过向量化操作让 Python 高效处理多维数组。
编程语言与软件工程2020 · 318 分 · 134 评入门 · 约 40 分钟编辑精选