arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.18877cs.SE
收藏

代码漏洞检测的代码行级语义结构学习

Line-level Semantic Structure Learning for Code Vulnerability Detection

Ziliang Wang, Ge Li, Jia Li, Yihong Dong, Yingfei Xiong, Zhi Jin

AI总结:

针对现有方法忽略代码结构信息的问题,提出CSLS网络,通过代码行级语义学习捕获结构关系,在Devign和Reveal数据集上取得最优性能。

摘要:

与自然语言的流动结构不同,编程语言在结构和语法上具有固有的刚性。然而,现有的基于预训练模型的检测方法通常将代码视为自然语言序列,忽略了其独特的结构信息。这阻碍了模型理解代码的语义和结构信息。为了解决这个问题,我们引入了通过代码行级语义学习实现代码结构感知网络(CSLS),该网络由四个组件组成:代码预处理、全局语义感知、代码行语义感知和代码行语义结构感知。预处理步骤将代码转换为两种类型的文本:全局代码文本和代码行级文本。与典型的预处理方法不同,CSLS保留换行符和缩进字符等结构元素,以增强模型在全局语义感知期间对代码行的感知。对于代码行语义结构感知,CSLS网络强调捕获代码行语义之间的结构关系。与基于代码块(控制流图)或标记的结构建模方法不同,CSLS使用代码行语义作为最小结构单元来学习非线性结构关系,从而提高代码漏洞检测的准确性。我们在来自真实项目的漏洞检测数据集上进行了大量实验。CSLS模型在代码漏洞检测方面优于最先进的基线,在Devign数据集上达到70.57%的准确率,在Reveal数据集上达到49.59%的F1分数。

英文摘要:

Unlike the flow structure of natural languages, programming languages have an inherent rigidity in structure and grammar.However, existing detection methods based on pre-trained models typically treat code as a natural language sequence, ignoring its unique structural information. This hinders the models from understanding the code's semantic and structual information.To address this problem, we introduce the Code Structure-Aware Network through Line-level Semantic Learning (CSLS), which comprises four components: code preprocessing, global semantic awareness, line semantic awareness, and line semantic structure awareness.The preprocessing step transforms the code into two types of text: global code text and line-level code text.Unlike typical preprocessing methods, CSLS retains structural elements such as newlines and indent characters to enhance the model's perception of code lines during global semantic awareness.For line semantics structure awareness, the CSLS network emphasizes capturing structural relationships between line semantics.Different from the structural modeling methods based on code blocks (control flow graphs) or tokens, CSLS uses line semantics as the minimum structural unit to learn nonlinear structural relationships, thereby improving the accuracy of code vulnerability detection.We conducted extensive experiments on vulnerability detection datasets from real projects. The CSLS model outperforms the state-of-the-art baselines in code vulnerability detection, achieving 70.57% accuracy on the Devign dataset and a 49.59% F1 score on the Reveal dataset.

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

↑