Semantic-Preserving Transformations as Mutation Operators: A Study on Their Effectiveness in Defect Detection

📄 arXiv: 2503.23448v1 📥 PDF

作者: Max Hort, Linas Vidziunas, Leon Moonen

分类: cs.SE, cs.AI, cs.CL, cs.LG

发布日期: 2025-03-30

备注: Accepted for publication in Mutation 2025 at the 18th IEEE International Conference on Software Testing, Verification and Validation (ICST 2025)


💡 一句话要点

探索语义保持变换作为变异算子在缺陷检测中的有效性

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 缺陷检测 语言模型 语义保持变换 集成学习 代码变异

📋 核心要点

  1. 现有缺陷检测工作主要集中在增强训练数据,以提高模型在语义相同代码上的鲁棒性,但忽略了在工具应用阶段利用语义相同代码进行改进。
  2. 本研究旨在通过将语义保持变换类比为变异算子,探索其在测试阶段提升缺陷检测工具性能的潜力。
  3. 实验结果表明,直接重用现有的语义保持变换并不能有效提高缺陷检测模型的准确性,且存在引入语义错误的风险。

📝 摘要(中文)

本文研究了语义保持变换在缺陷检测工具测试阶段的增强效果,类似于变异测试。研究首先收集了已实现的语义保持变换,并实证研究了三种不同的集成策略,以增强缺陷检测工具。研究人员将收集到的变换应用于Devign数据集,并将漏洞视为一种缺陷,使用了两个微调的大型语言模型(VulBERTa、PLBART)进行缺陷检测。结果表明,虽然收集到了大量变换,但经过手动检查发现许多变换会改变代码语义。使用剩余的正确变换和三种集成策略,未能提高缺陷检测模型的准确性。研究结果表明,重用共享的语义保持变换是困难的,有时甚至会导致错误的语义更改。

🔬 方法详解

问题定义:论文旨在解决缺陷检测工具在实际应用中,由于代码变异导致性能下降的问题。现有方法主要集中在训练阶段增强模型的鲁棒性,缺乏在测试阶段利用代码等价变异来提升检测效果的手段。现有语义保持变换的质量和可用性未知,直接应用可能引入错误。

核心思路:论文的核心思路是将语义保持变换作为变异算子,在测试阶段对输入代码进行变换,然后利用集成策略将多个变换后结果进行融合,从而提高缺陷检测工具的鲁棒性和准确性。通过这种方式,模拟真实世界中代码的各种变异情况,检验和提升缺陷检测工具的性能。

技术框架:整体流程包括以下几个步骤:1) 收集现有的语义保持变换实现;2) 筛选出真正保持语义的变换;3) 将这些变换应用于Devign数据集中的代码;4) 使用VulBERTa和PLBART两个预训练语言模型进行缺陷检测;5) 采用三种集成策略(具体策略未知)融合多个变换后的检测结果;6) 评估集成策略对缺陷检测准确率的影响。

关键创新:该研究的关键创新在于将语义保持变换应用于缺陷检测工具的测试阶段,并探索了不同的集成策略。这是一种新的视角,旨在提高缺陷检测工具在实际应用中的鲁棒性,而不仅仅是在训练阶段。此外,论文还对现有语义保持变换的质量进行了评估,指出了其潜在的问题。

关键设计:论文的关键设计包括:1) 收集和筛选语义保持变换的具体标准(例如,手动检查);2) 三种集成策略的具体实现方式(未知);3) VulBERTa和PLBART模型的微调细节(未知);4) Devign数据集的使用方式(例如,如何划分训练集、验证集和测试集)。这些细节对实验结果至关重要,但论文摘要中并未详细描述。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

研究收集了28篇出版物中的94种不同变换,并实现了其中4篇出版物的39种变换。然而,手动检查发现其中23种变换实际上改变了代码语义。使用剩余的16种正确变换和三种集成策略,未能提高VulBERTa和PLBART在Devign数据集上的缺陷检测准确率。该结果表明,直接重用现有的语义保持变换可能存在问题。

🎯 应用场景

该研究成果可应用于软件安全测试领域,帮助开发者更有效地评估和改进缺陷检测工具。通过模拟真实代码变异,可以提高缺陷检测工具的鲁棒性和准确性,从而减少软件漏洞,提升软件质量。未来的研究可以探索更有效的语义保持变换和集成策略。

📄 摘要(原文)

Recent advances in defect detection use language models. Existing works enhanced the training data to improve the models' robustness when applied to semantically identical code (i.e., predictions should be the same). However, the use of semantically identical code has not been considered for improving the tools during their application - a concept closely related to metamorphic testing. The goal of our study is to determine whether we can use semantic-preserving transformations, analogue to mutation operators, to improve the performance of defect detection tools in the testing stage. We first collect existing publications which implemented semantic-preserving transformations and share their implementation, such that we can reuse them. We empirically study the effectiveness of three different ensemble strategies for enhancing defect detection tools. We apply the collected transformations on the Devign dataset, considering vulnerabilities as a type of defect, and two fine-tuned large language models for defect detection (VulBERTa, PLBART). We found 28 publications with 94 different transformations. We choose to implement 39 transformations from four of the publications, but a manual check revealed that 23 out 39 transformations change code semantics. Using the 16 remaining, correct transformations and three ensemble strategies, we were not able to increase the accuracy of the defect detection models. Our results show that reusing shared semantic-preserving transformation is difficult, sometimes even causing wrongful changes to the semantics. Keywords: defect detection, language model, semantic-preserving transformation, ensemble