Out of Distribution, Out of Luck: How Well Can LLMs Trained on Vulnerability Datasets Detect Top 25 CWE Weaknesses?

Yikun Li, Ngoc Tan Bui, Ting Zhang, Martin Weyssow, Chengran Yang, Xin Zhou, Jinfeng Jiang, Junkai Chen, Huihui Huang, Huu Hung Nguyen, Chiok Yew Ho, Jie Tang, Ruiyin Li, Yide Yin, Han Wei Ang, Frank Liauw, Eng Lieh Ouh, Lwin Khin Shar, David LoarXiv 2025 · DOI

Abstract

Automated vulnerability detection remains a significant challenge in software security, primarily due to a "generalization gap" where models excel on training data but fail on real-world code. This paper identifies critical flaws in existing datasets, including high redundancy and poor label quality. To address these, the authors introduce TitanVul, a curated training set, and BenchVul, a balanced benchmark for the MITRE Top 25 CWEs. Their findings demonstrate that high-quality data curation and synthetic augmentation are essential for bridging the gap between laboratory performance and real-world utility.

The Generalization Gap in Vulnerability Detection

Automated vulnerability detection is often evaluated using In-Distribution (ID) settings, where models are tested on a subset of their training data. However, this approach masks a massive failure in real-world, Out-of-Distribution (OOD) performance. The authors identify three primary drivers of this gap:

  1. Unreliable Evaluation: Many existing datasets suffer from extreme redundancy and noisy labels. Overlaps between datasets can reach as high as 71%, leading models to memorize specific code patterns rather than learning underlying security principles.
  2. Poor Data Quality: Datasets often include non-security-related code changes, such as refactoring, which confuses the learning process.
  3. The Long Tail Problem: Critical but rare vulnerabilities (the MITRE Top 25) are often underrepresented, leaving models unprepared for high-risk scenarios.
Figure 2: Heatmap illustrating the significant overlap and redundancy between popular vulnerability datasets, with some pairs showing over 71% similarity.

Methods: TitanVul and BenchVul

To solve these issues, the authors developed a three-pronged approach:

  • TitanVul (Training Set): An aggregation of seven public datasets subjected to rigorous deduplication and a multi-agent LLM verification pipeline. This pipeline (Auditor, Critic, and Consensus agents) ensures that each sample represents a genuine security fix, resulting in a high-quality set of 38,548 functions.
  • BenchVul (Benchmark): A manually verified, balanced test set covering the MITRE Top 25 CWEs. By providing exactly 50 samples per category, BenchVul ensures that rare vulnerabilities are given equal weight in evaluation.
  • Realistic Vulnerability Generation (RVG): A pipeline that uses LLMs to simulate development workflows, creating high-quality synthetic data for rare vulnerabilities that are otherwise scarce in public datasets.
Figure 3: Distribution of CWE types across various existing datasets, highlighting the severe imbalance and "long tail" problem where many critical weaknesses are rarely represented.

Key Insights and Results

The ID vs. OOD Disconnect

The study reveals a stark contrast between leaderboard performance and real-world efficacy. For instance, the BigVul dataset achieved a high ID accuracy of 0.703 but plummeted to 0.493 on OOD samples—essentially no better than a coin flip. This confirms that high scores on standard benchmarks often indicate overfitting to dataset-specific quirks.

The Power of Quality and Augmentation

TitanVul significantly outperformed existing datasets, achieving an OOD accuracy of 0.881. When augmented with synthetic data from the RVG pipeline, performance on real-world vulnerabilities rose to 0.932. This improvement was particularly notable for rare types like hard-coded credentials (CWE-798), proving that synthetic data can act as a force multiplier for specialized security tasks.

LLM Baselines

Interestingly, general-purpose models like GPT-4 and Claude-3.7 showed modest performance (0.5–0.7 accuracy) in zero-shot or few-shot settings. This highlights that while LLMs are powerful, specialized fine-tuning on high-quality, verified security data remains necessary for reliable vulnerability detection.

Limitations and Future Work

The current research focuses on function-level analysis, whereas many real-world vulnerabilities are inter-procedural, involving interactions across multiple files. Future work will aim to expand the benchmark to include these complex scenarios and broader industrial codebases, while also addressing potential biases inherent in LLM-generated synthetic data.

Summary updated

BibTeX
@misc{li2025out,
  author = {Yikun Li and Ngoc Tan Bui and Ting Zhang and Martin Weyssow and Chengran Yang and Xin Zhou and Jinfeng Jiang and Junkai Chen and Huihui Huang and Huu Hung Nguyen and Chiok Yew Ho and Jie Tang and Ruiyin Li and Yide Yin and Han Wei Ang and Frank Liauw and Eng Lieh Ouh and Lwin Khin Shar and David Lo},
  title = {{Out of Distribution, Out of Luck: How Well Can LLMs Trained on Vulnerability Datasets Detect Top 25 CWE Weaknesses?}},
  year = {2025},
  eprint = {2507.21817},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.21817},
}
Figure