VulDeePecker: A Deep Learning-Based System for Vulnerability Detection

Zhen Li, Deqing Zou, Shouhuai Xu, Xinyu Ou, Hai Jin, Sujuan Wang, Zhijun Deng, Yuyi Zhong

Abstract

Software vulnerability detection has traditionally relied on manual feature engineering or simple code similarity checks, both of which struggle with scalability and accuracy. This paper presents VulDeePecker, the first deep learning-based system for vulnerability detection that leverages "code gadgets" to represent program logic. By using program slicing to extract semantically related code fragments and employing Bidirectional Long Short-Term Memory (BLSTM) networks, VulDeePecker automates feature extraction while maintaining contextual awareness. Evaluation on real-world projects demonstrates its ability to detect previously unlisted vulnerabilities, marking a significant advancement in automated security analysis.

Introduction

The rapid growth of software complexity has made manual vulnerability detection increasingly impractical. Traditional approaches generally fall into two categories: static analysis tools, which require experts to manually define vulnerability patterns, and code similarity detectors, which identify clones of known bugs. While static analysis is prone to high false-negative rates due to subjective rule definitions, similarity detectors fail to identify vulnerabilities that are not direct copies. VulDeePecker addresses these limitations by applying deep learning to automatically learn vulnerability features from code representations that preserve semantic meaning.

The VulDeePecker Framework

The core innovation of VulDeePecker is the "code gadget." Unlike natural language processing, where text is treated as a linear sequence, source code contains complex data and control dependencies. To bridge this gap, VulDeePecker uses program slicing to group lines of code that are semantically related to specific "key points," such as library or API calls (e.g., memcpy, malloc). While the system automates feature extraction, human expertise is utilized to define these key points; the authors found that monitoring specific API calls rather than all of them improved the F1-score by approximately 7.5%.

Overview of the VulDeePecker system workflow.

The system operates in two primary phases: the learning phase and the detection phase. In the learning phase, training programs are processed to extract library/API function calls and their corresponding program slices. These slices are assembled into code gadgets and labeled as vulnerable or non-vulnerable.

Generation of code gadgets from source code.

To ensure the model generalizes across different codebases, user-defined variables and functions are replaced with generic symbolic tokens (e.g., VAR1, FUN1). This prevents the model from memorizing specific names and instead focuses on the underlying patterns of vulnerabilities. These symbolic representations are then converted into vectors using Word2Vec and fed into a Bidirectional Long Short-Term Memory (BLSTM) network. The bidirectional nature of the network is critical, as vulnerabilities often depend on context both preceding and following a specific line of code.

Experimental Evaluation

To evaluate VulDeePecker, the authors created a benchmark dataset using the National Vulnerability Database (NVD) and the Software Assurance Reference Dataset (SARD), focusing on Buffer Errors (CWE-119) and Resource Management Errors (CWE-399). The final dataset comprised over 61,000 code gadgets.

VulDeePecker demonstrated superior performance compared to traditional tools like Flawfinder, RATS, and Checkmarx. On the Buffer Error dataset, VulDeePecker achieved a False Negative Rate (FNR) of just 7.0%, a dramatic improvement over Checkmarx's 41.1%. Furthermore, when applied to real-world software such as Xen and Libav, the system successfully identified four vulnerabilities that had been "silently patched" and were not listed in the NVD.

Conclusion

VulDeePecker represents a significant step toward fully automated vulnerability detection. By combining program slicing with deep learning, it moves beyond simple syntax matching to understand program semantics. While currently limited to C/C++ and vulnerabilities tied to API calls, future work aims to expand its scope to include pointer-related bugs and binary analysis. The public release of the code gadget dataset provides a valuable resource for the research community to further advance deep learning-based security tools.

Summary updated

BibTeX
@inproceedings{li2018vuldeepecker,
  author = {Zhen Li and Deqing Zou and Shouhuai Xu and Xinyu Ou and Hai Jin and Sujuan Wang and Zhijun Deng and Yuyi Zhong},
  title = {{VulDeePecker: A Deep Learning-Based System for Vulnerability Detection}},
  booktitle = {NDSS},
  year = {2018},
}
Figure