Mitigating fix reversal: Counterfactual constraints for function-level vulnerability detection
Yun Bian, Shihao Li, Haiquan Wang, Yi Chen, Zhao Yang, Zhe Cui
Key points
From the paper's conclusion- We propose CFVul to address this problem.
Abstract
Function-level vulnerability detectors often exhibit fix reversal, assigning a higher vulnerability probability to a fixed version than to its vulnerable counterpart. Fixes usually lengthen functions, and larger length increases are associated with more severe reversal. Code-transformation experiments indicate that fix reversal mainly stems from a length shortcut: vulnerability probability increases with function length when content is fixed. We propose CFVul to address this problem. Sliding-window encoding covers complete functions, retaining fix information beyond the truncation boundary. During training, a content constraint encourages the vulnerable version to receive a higher vulnerability probability under a common length input. During inference, a length constraint averages vulnerability probabilities over fixed reference lengths, reducing the influence of actual length changes. On PrimeVul, CFVul achieves a fix-pair ranking metric, PairRank, of 59.4\%, exceeding the existing methods compared. For fixes that increase function length by more than 15\%, PairRank rises from CodeBERT's 25.8\% to 48.4\%. PairRank also improves in experiments with four additional models and three additional datasets. By weakening the length shortcut, CFVul reduces cases in which fixed versions receive higher vulnerability probabilities than vulnerable versions. It requires only existing fix pairs and applies to multiple pretrained code models, facilitating adoption in existing detectors.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- PatchCon: Patch-aware Weighted Supervised Contrastive Learning for Vulnerability DetectionarXiv · 2026
- Embedding Drift in Code Vulnerability Models Under Intended Behaviour-Preserving TransformationsarXiv · 2026
- Beyond the Diff - VulSpot: A Vulnerability Dataset Where No Vulnerability Goes UnlocalizedarXiv · 2026
- Cyber-JEV: Matched Contrastive Fine-Tuning of Language Models for Fast Source-Code Vulnerability TriagearXiv · 2026
- Right Verdict, Right Reason? An Execution-Grounded Study of Whether LLM Vulnerability Detectors Understand VulnerabilitiesarXiv · 2026
- Fine-Grained Reasoning Enhanced Vulnerability Patch Generation with Multi-View Fix KnowledgeACM Transactions on Software Engineering and Methodology · 2026