Deep Learning-Based Out-of-distribution Source Code Data Identification: How Far Have We Gone?

Van Nguyen, Xingliang Yuan, Tingmin Wu, Surya Nepal, Marthie Grobler, Carsten RudolpharXiv 2024 · DOI

Abstract

Software Vulnerability Detection (SVD) models often suffer from "silent failures" when encountering out-of-distribution (OOD) data—code patterns or categories not present during training. This paper presents LEO, a framework that integrates information-theoretic feature selection with cluster-contrastive learning to identify OOD source code. By focusing on label-relevant code statements and creating distinct latent clusters for different vulnerability types, LEO significantly improves detection performance over traditional computer vision-based OOD methods, reducing false positive rates by over 15%.

Introduction

The integration of Deep Learning (DL) into Software Vulnerability Detection (SVD) has yielded impressive results. However, these models face a critical challenge: the Out-of-Distribution (OOD) problem. When presented with code from a category it has never seen—such as a new Common Weakness Enumeration (CWE)—a standard SVD model may classify it with high confidence despite the lack of familiarity. This "silent failure" poses a significant security risk.

While OOD detection is a mature field in computer vision, source code presents unique structural and semantic complexities. Vulnerabilities are not simple visual patterns but are often subtle flaws buried within boilerplate code. Existing techniques designed for images often fail to capture these intricate relationships.

Methodology: The LEO Framework

The proposed framework, LEO, addresses these challenges through a two-phase approach focused on robust data representation.

The LEO framework overview, showing the selection network $\zeta$, the latent space with cluster-contrastive learning, and the final classifier.

1. Selection Network and Information-Theoretic Guidance

Rather than processing an entire code block, LEO employs a selection network ($\zeta$) to identify "important" statements—those most likely to contain the vulnerability. To make this discrete selection process differentiable, the model utilizes the Gumbel-Softmax trick. To ensure the network selects meaningful lines, LEO maximizes the Mutual Information between the selected statements and the ground-truth labels. This effectively filters out "background noise" (standard, non-vulnerable code) and focuses the model on the actual flaw.

Visual representation of the selection network identifying critical code statements (highlighted) within larger functions.

2. Cluster-Contrastive Learning

A key innovation of LEO is its treatment of vulnerabilities as a heterogeneous group. Instead of a single "vulnerable" class, LEO uses k-means clustering in the latent space to group similar vulnerability patterns. By pushing different patterns and non-vulnerable code apart, the model creates sharper boundaries for "In-Distribution" (ID) data.

3. Inference and Outlier Scoring

During deployment, LEO calculates an outlier score for new code samples using the Mahalanobis distance. If a sample falls significantly outside the established clusters of the training data, it is flagged as OOD, preventing the model from making a high-confidence but incorrect prediction.

Experimental Evaluation

The authors evaluated LEO using DiverseVul, a large-scale dataset containing over 18,000 vulnerable and 330,000 non-vulnerable C/C++ functions across 150 CWE categories. By designating specific CWEs as ID and others as OOD, the researchers simulated real-world "zero-day" scenarios.

Key Results

LEO was benchmarked against state-of-the-art OOD baselines (e.g., SSD, Outlier Exposure) and SVD models (e.g., CodeBERT).

  • Performance: LEO improved the False Positive Rate (FPR at TPR 95%) by an average of 15.27%.
  • Reliability: The model showed a 7.39% increase in AUROC and a 4.93% increase in AUPR compared to the best existing baselines.
  • Latent Space Clarity: Qualitative analysis via t-SNE visualizations confirmed that LEO produces tighter, more distinct clusters for ID data, making OOD samples significantly easier to identify as outliers.

Discussion and Future Work

LEO demonstrates that focusing on label-relevant features and acknowledging the diversity of vulnerability patterns is crucial for effective OOD detection in source code. However, several areas for improvement remain:

  • Language Support: Currently optimized for C/C++, extending LEO to Python or Java would require adjustments to preprocessing and embedding layers.
  • Computational Complexity: The iterative k-means clustering during training adds overhead, though it remains manageable on modern hardware.
  • Thresholding: Setting the optimal outlier threshold remains a challenge in adversarial environments.

Future research may explore the integration of LEO with Large Language Models (LLMs) to further refine the semantic understanding of complex code patterns.

Summary updated

BibTeX
@misc{nguyen2024deep,
  author = {Van Nguyen and Xingliang Yuan and Tingmin Wu and Surya Nepal and Marthie Grobler and Carsten Rudolph},
  title = {{Deep Learning-Based Out-of-distribution Source Code Data Identification: How Far Have We Gone?}},
  year = {2024},
  eprint = {2404.05964},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.05964},
}
Figure