On Distribution Shift in Learning-based Bug Detectors
Jingxuan He, Luca Beurer-Kellner, Martin T. Vechev
Abstract
Deep learning has recently achieved initial success in program analysis tasks such as bug detection. Lacking real bugs, most existing works construct training and test data by injecting synthetic bugs into correct programs. Despite achieving high test accuracy (e.g., >90%), the resulting bug detectors are found to be surprisingly unusable in practice, i.e., <10% precision when used to scan real software repositories. In this work, we argue that this massive performance difference is caused by a distribution shift, i.e., a fundamental mismatch between the real bug distribution and the synthetic bug distribution used to train and evaluate the detectors. To address this key challenge, we propose to train a bug detector in two phases, first on a synthetic bug distribution to adapt the model to the bug detection domain, and then on a real bug distribution to drive the model towards the real distribution. During these two phases, we leverage a multi-task hierarchy, focal loss, and contrastive learning to further boost performance. We evaluate our approach extensively on three widely studied bug types, for which we construct new datasets carefully designed to capture the real bug distribution. The results demonstrate that our approach is practically effective and successfully mitigates the distribution shift: our learned detectors are highly performant on both our test set and the latest version of open source repositories. Our code, datasets, and models are publicly available at https://github.com/eth-sri/ learning-real-bug-detector .
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
10 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Large Language Models of Code Fail at Completing Code with Potential Bugs cites Global Relational Models of Source Code
- OctoPack: Instruction Tuning Code Large Language Models cites Global Relational Models of Source Code
- CodeBERT: A Pre-Trained Model for Programming and Natural Languages cites Learning and Evaluating Contextual Embedding of Source Code
- Learning and Evaluating Contextual Embedding of Source Code cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Learning and Evaluating Contextual Embedding of Source Code cites Global Relational Models of Source Code
- Data Quality for Software Vulnerability Datasets cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Large Language Models for Code: Security Hardening and Adversarial Testing cites Data Quality for Software Vulnerability Datasets
- Large Language Models for Code: Security Hardening and Adversarial Testing cites WILDS: A Benchmark of in-the-Wild Distribution Shifts
- Uncovering the Limits of Machine Learning for Automatic Vulnerability Detection cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
Cited by top-tier papers10
- OctoPack: Instruction Tuning Code Large Language ModelsNiklas Muennighoff, Qian Liu, Armel Randy Zebaze, Qinkai Zheng et al.ICLR 2024 · 203 citations
- Data Quality for Software Vulnerability DatasetsRoland Croft, Muhammad Ali Babar, M. Mehdi KholoosiICSE 2023 · 138 citations
- Large Language Models for Code: Security Hardening and Adversarial TestingJingxuan He, Martin T. VechevCCS 2023 · 98 citations
- Uncovering the Limits of Machine Learning for Automatic Vulnerability DetectionNiklas Risse, Marcel BöhmeUSENIX Security 2024 · 63 citations
- Large Language Models of Code Fail at Completing Code with Potential BugsTuan Dinh, Jinman Zhao, Samson Tan, Renato Negrinho et al.NeurIPS 2023 · 59 citations
Builds on20
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan et al.EMNLP Findings 2020 · 2,828 citations
- WILDS: A Benchmark of in-the-Wild Distribution ShiftsPang Wei Koh, Shiori Sagawa, Henrik Marklund, Sang Michael Xie et al.ICML 2021 · 1,773 citations
- Dice Loss for Data-imbalanced NLP TasksXiaoya Li, Xiaofei Sun, Yuxian Meng, Junjun Liang et al.ACL 2020 · 575 citations
- Learning and Evaluating Contextual Embedding of Source CodeAditya Kanade, Petros Maniatis, Gogul Balakrishnan, Kensen ShiICML 2020 · 438 citations
- Global Relational Models of Source CodeVincent J. Hellendoorn, Charles Sutton, Rishabh Singh, Petros Maniatis et al.ICLR 2020 · 252 citations
Related papers
- How to Train Your Neural Bug Detector: Artificial vs Real BugsCedric Richter, Heike WehrheimASE 2023 · 5 citations
- CLeVeR: Multi-modal Contrastive Learning for Vulnerability Code RepresentationJiayuan Li, Lei Cui, Sen Zhao, Yun Yang et al.ACL Findings 2025 · 4 citations
- Robust Learning of Deep Predictive Models from Noisy and Imbalanced Software Engineering DatasetsZhong Li, Minxue Pan, Yu Pei, Tian Zhang et al.ASE 2022 · 10 citations
- Finding Bugs Using Your Own Code: Detecting Functionally-similar yet Inconsistent CodeMansour Ahmadi, Reza Mirzazade Farkhani, Ryan Williams, Long LuUSENIX Security 2021 · 41 citations
- Self-Supervised Bug Detection and RepairMiltiadis Allamanis, Henry Jackson-Flux, Marc BrockschmidtNeurIPS 2021 · 145 citations
