arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2503.08486cs.SEcs.FL
收藏

利用符号化解析从代码中推断输入文法

Inferring Input Grammars from Code with Symbolic Parsing

Leon Bettscheider, Andreas Zeller

AI总结:

本文提出符号化解析技术,首次从递归下降解析器代码中自动挖掘输入文法,通过限制递归与循环、为每条路径生成展开备选,无需种子输入即可高准确率提取文法。

摘要:

为软件系统生成有效的测试输入要求这些输入必须是合法的,否则它们会在到达实际功能之前就被拒绝。在缺乏输入语言规范的情况下,常见的测试生成技术依赖于样本输入,这些样本输入被抽象为匹配的文法和/或在测试覆盖率的引导下进行演化。然而,如果样本输入遗漏了输入语言的某些特性,那么随机生成这些特性的机会就很渺茫。在这项工作中,我们提出了第一种从递归下降解析器的代码中符号化地、自动地挖掘输入文法的技术。迄今为止,解析器的复杂性使得这种符号化分析极具挑战性甚至不可能实现。我们实现的符号化解析技术通过以下方式克服了这些挑战:(1)将每个解析器函数 parse_ELEM() 与非终结符 <ELEM> 关联起来;(2)限制递归调用和循环迭代次数,使得对 parse_ELEM() 的符号化分析只需考虑有限数量的路径;(3)为每条路径创建 <ELEM> 的一个展开备选项。由于是纯静态的,符号化解析不需要种子输入;由于它缓解了路径爆炸问题,因此可以扩展到复杂的解析器。我们的评估表明符号化解析具有很高的准确性。应用于 TINY-C 或 JSON 等复杂语言的解析器时,我们的 STALAGMITE 实现提取文法的准确率达到 99--100%,尽管只需要程序代码而不需要输入样本,却大幅超越了现有技术水平。所得到的文法覆盖了整个输入空间,从而支持全面有效的测试生成、逆向工程和文档化。

英文摘要:

Generating effective test inputs for a software system requires that these inputs be valid, as they will otherwise be rejected without reaching actual functionality. In the absence of a specification for the input language, common test generation techniques rely on sample inputs, which are abstracted into matching grammars and/or evolved guided by test coverage. However, if sample inputs miss features of the input language, the chances of generating these features randomly are slim. In this work, we present the first technique for symbolically and automatically mining input grammars from the code of recursive descent parsers. So far, the complexity of parsers has made such a symbolic analysis challenging to impossible. Our realization of the symbolic parsing technique overcomes these challenges by (1) associating each parser function parse_ELEM() with a nonterminal <ELEM>; (2) limiting recursive calls and loop iterations, such that a symbolic analysis of parse_ELEM() needs to consider only a finite number of paths; and (3) for each path, create an expansion alternative for <ELEM>. Being purely static, symbolic parsing does not require seed inputs; as it mitigates path explosion, it scales to complex parsers. Our evaluation promises symbolic parsing to be highly accurate. Applied on parsers for complex languages such as TINY-C or JSON, our STALAGMITE implementation extracts grammars with an accuracy of 99--100%, widely improving over the state of the art despite requiring only the program code and no input samples. The resulting grammars cover the entire input space, allowing for comprehensive and effective test generation, reverse engineering, and documentation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑