高级检索

    基于大语言模型的源代码漏洞检测方法研究与应用

    Research and Application of Source Code Vulnerability Detection Methods Based on Large Language Models

    • 摘要: 针对现有大语言模型在源代码漏洞检测中对程序结构信息利用不足、推理稳定性较弱以及微调成本较高等问题,本文提出一种融合图结构表征与大语言模型推理能力的漏洞检测方法。该方法以源代码数据流图为基础,对变量依赖关系和语义传播路径进行建模,并通过跨模态映射将图结构特征对齐到语言模型语义空间,实现程序结构知识的有效注入。同时,设计基于代码重构任务的渐进式图编码器预训练策略,以增强模型对漏洞相关结构模式的感知能力。在此基础上,结合结构化推理蒸馏与低秩自适应参数高效微调机制,在降低训练开销的同时提升漏洞判别性能。进一步,引入面向漏洞检测的思维链推理流程,增强检测结果的可解释性与推理一致性。实验结果表明,该方法能够有效提升源代码漏洞检测的准确性和稳定性。

       

      Abstract: To address the limitations of large language models (LLMs) in source code vulnerability detection—namely insufficient utilization of program structural information, unstable reasoning processes, and high fine-tuning costs—this paper proposes a vulnerability detection framework that integrates graph-based representations with LLM reasoning capabilities. The proposed method constructs data flow graphs (DFGs) from source code to model variable dependencies and semantic propagation paths, and aligns graph features with the semantic embedding space of LLMs through a cross-modal mapping module, enabling effective injection of structural knowledge into the language model. Furthermore, a progressive pretraining strategy based on code reconstruction tasks is designed to enhance the graph encoder’s ability to capture vulnerability-related structural patterns. On this basis, structured reasoning distillation and parameter-efficient fine-tuning via Low-Rank Adaptation (LoRA) are incorporated to transfer vulnerability analysis knowledge from teacher models to student models, improving detection performance while reducing training overhead. In addition, a chain-of-thought reasoning process tailored for vulnerability detection is introduced to improve interpretability and reasoning consistency. Experimental results demonstrate that the proposed method significantly improves both the accuracy and robustness of source code vulnerability detection while maintaining low fine-tuning cost.

       

    /

    返回文章
    返回