Learning to Focus: Context Extraction for Efficient Code Vulnerability Detection with Language Models

Fuente: arXiv
Salvato in:
Dettagli Bibliografici
Autori principali: Zheng, Xinran, Qian, Xingzhi, Zhou, Huichi, Yang, Shuo, He, Yiling, Jana, Suman, Cavallaro, Lorenzo
Natura: Preprint
Pubblicazione: 2025
Soggetti:
Accesso online:
Tags: Aggiungi Tag
Nessun Tag, puoi essere il primo ad aggiungerne!!
_version_ 1866918091219271680
author Zheng, Xinran
Qian, Xingzhi
Zhou, Huichi
Yang, Shuo
He, Yiling
Jana, Suman
Cavallaro, Lorenzo
author_facet Zheng, Xinran
Qian, Xingzhi
Zhou, Huichi
Yang, Shuo
He, Yiling
Jana, Suman
Cavallaro, Lorenzo
contents Language models (LMs) show promise for vulnerability detection but struggle with long, real-world code due to sparse and uncertain vulnerability locations. These issues, exacerbated by token limits, often cause models to miss vulnerability-related signals, thereby impairing effective learning. A key intuition is to enhance LMs with concise, information-rich context. Commit-based annotations offer precise, CWE-agnostic supervision, but are unavailable during inference, as they depend on historical code changes. Moreover, their extreme sparsity, often covering only a few lines, makes it difficult for LMs to process directly. In this paper, we propose FocusVul, a model-agnostic framework that improves LM-based vulnerability detection by learning to select sensitive context. FocusVul learns commit-based annotation patterns through hierarchical semantic modeling and generalizes them to identify line-level vulnerability-relevant regions during inference. It then extracts LM-oriented context via both dependency and execution flows surrounding selected regions, yielding semantically rich inputs for effective vulnerability detection. Experiments on real-world benchmarks show that FocusVul consistently outperforms heuristic-based and full-function fine-tuning approaches, improving classification performance by 164.04% and reducing FLOPs by 19.12% on average.
format Preprint
id arxiv_https___arxiv_org_abs_2505_17460
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Learning to Focus: Context Extraction for Efficient Code Vulnerability Detection with Language Models
Zheng, Xinran
Qian, Xingzhi
Zhou, Huichi
Yang, Shuo
He, Yiling
Jana, Suman
Cavallaro, Lorenzo
Software Engineering
Language models (LMs) show promise for vulnerability detection but struggle with long, real-world code due to sparse and uncertain vulnerability locations. These issues, exacerbated by token limits, often cause models to miss vulnerability-related signals, thereby impairing effective learning. A key intuition is to enhance LMs with concise, information-rich context. Commit-based annotations offer precise, CWE-agnostic supervision, but are unavailable during inference, as they depend on historical code changes. Moreover, their extreme sparsity, often covering only a few lines, makes it difficult for LMs to process directly. In this paper, we propose FocusVul, a model-agnostic framework that improves LM-based vulnerability detection by learning to select sensitive context. FocusVul learns commit-based annotation patterns through hierarchical semantic modeling and generalizes them to identify line-level vulnerability-relevant regions during inference. It then extracts LM-oriented context via both dependency and execution flows surrounding selected regions, yielding semantically rich inputs for effective vulnerability detection. Experiments on real-world benchmarks show that FocusVul consistently outperforms heuristic-based and full-function fine-tuning approaches, improving classification performance by 164.04% and reducing FLOPs by 19.12% on average.
title Learning to Focus: Context Extraction for Efficient Code Vulnerability Detection with Language Models
topic Software Engineering
url https://arxiv.org/abs/2505.17460