一句话:用嵌入模型预筛候选、GCN 求近似最优顶点匹配的两阶段加速方法,缓解噪声干扰并高效检测代码缺陷。
基于代码相似度的缺陷检测常将代码片段视为图并比较相似度,但缺陷逻辑常只涉及少量语句,其余语句成为噪声,严重干扰相似度度量。最优顶点匹配理论上可解决,但该任务 NP 完全,难以扩展至大规模代码库。为此,本文提出两阶段加速策略:第一阶段训练顶点匹配嵌入模型,从目标代码库快速筛选出与已知缺陷种子匹配度较高的少量候选代码图;第二阶段基于图卷积神经网络构建高阶相似度嵌入模型,高效求得近似最优的顶点匹配并计算图相似度以识别潜在缺陷代码。在五个开源项目上共发现 31 个未知缺陷并获开发者确认,检测效率提升数十倍。
Various techniques based on code similarity measurement have been proposed to detect bugs. Essentially, the code fragment can be regarded as a kind of graph. Performing code graph similarity comparison to identify the potential bugs is a natural choice. However, the logic of a bug often involves only a few statements in the code fragment, while others are bug-irrelevant. They can be considered as a kind of noise, and can heavily interfere with the code similarity measurement. In theory, performing optimal vertex matching can address the problem well, but the task is NP-complete and cannot be applied to a large-scale code base. In this paper, we propose a two-phase strategy to accelerate code graph vertex matching for detecting bugs. In the first phase, a vertex matching embedding model is trained and used to rapidly filter a limited number of candidate code graphs from the target code base, which are likely to have a high vertex matching degree with the seed, i.e., the known buggy code. As a result, the number of code graphs needed to be further analyzed is dramatically reduced. In the second phase, a high-order similarity embedding model based on graph convolutional neural network is built to efficiently get the approximately optimal vertex matching between the seed and candidates. On this basis, the code graph similarity is calculated to identify the potential buggy code. The proposed method is applied to five open source projects. In total, 31 unknown bugs were successfully detected and confirmed by developers. Comparative experiments demonstrate that our method can effectively mitigate the noise problem, and the detection efficiency can be improved dozens of times with the two-phase strategy.
DOI 原文 ·
@inproceedings{paperbot7388,
title = {Hunting bugs with accelerated optimal graph vertex matching},
author = {Xiaohui Zhang and Yuanjun Gong and Bin Liang and Jianjun Huang and Wei You and Wenchang Shi and Jian Zhang},
booktitle = {ISSTA},
year = {2022},
doi = {10.1145/3533767.3534393}
}