Fix Pattern-Aware Vulnerability Patch Generation via In-Context Learning

With the rapid advancement of deep learning technologies, numerous large language models (LLMs) have been developed, achieving remarkable performance across various tasks. Nevertheless, in the field of vulnerability patch generation, previous studies still face notable limitations: (1) Insufficient context. LLM-based approaches often rely on a single vulnerable function as prompt input for generating patches, which prevents the model from utilizing adequate contextual information and limits its ability to produce accurate patches. (2) Difficulties in extracting effective fix patterns. The substantial semantic differences between various vulnerabilities result in a wide range of fix patterns. Consequently, automatically extracting effective fix patterns tailored to specific vulnerabilities becomes a significant challenge. To address this, we propose PailGen, a novel fix P attern- a ware, i n-context l earning-incorporated vulnerability patch Gen eration approach. PailGen comprises three main modules: hybrid patch retrieval module, fix pattern mining module and in-context learning-incorporated patch generation module. (1) Hybrid patch retrieval module, aims at retrieving the top- \(k\) relevant vulnerability-fix pairs from the existing codebase by combining BM25 and Dense Passage Retriever (DPR) to construct a hybrid patch retriever. (2) Fix pattern mining module, aims at extracting effective fix patterns from the relevant vulnerability-fix pairs by leveraging an automatic fix pattern mining strategy based on Abstract Syntax Tree (AST). Fix patterns are designed to analyze code changes at different levels (e.g., expression level and statement level). (3) In-context learning-incorporated patch generation module, aims at providing comprehensive contextual information for LLMs by integrating the vulnerable code, its AST, the relevant patches and the extracted fix patterns into the prompt input. Overall, PailGen delivers better demonstrations for in-context learning and provides more comprehensive semantic guidance for patch generation, enabling LLMs to effectively address vulnerabilities. We evaluate PailGen on two real-world C/C++ vulnerability datasets. The experimental results demonstrate that PailGen achieves the best performance, outperforming all baseline approaches.

Authors

Institutions

Publication Details

Journal
ACM Transactions on Software Engineering and Methodology
Published
2026-02-09
DOI
https://doi.org/10.1145/3796512
Primary Topic
Adversarial Robustness in Machine Learning
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Fix Pattern-Aware Vulnerability Patch Generation via In-Context Learning

Cuiyun Gao, Yi-Xiang Wang, Miaomiao Shao, Yuxin Ding et al.
ACM Transactions on Software Engineering and Methodology
Adversarial Robustness in Machine Learning
article

Fix Pattern-Aware Vulnerability Patch Generation via In-Context Learning

Cuiyun Gao, Yi-Xiang Wang, Miaomiao Shao, Yuxin Ding, Guoqing Zhu
article en

Abstract

With the rapid advancement of deep learning technologies, numerous large language models (LLMs) have been developed, achieving remarkable performance across various tasks. Nevertheless, in the field of vulnerability patch generation, previous studies still face notable limitations: (1) Insufficient context. LLM-based approaches often rely on a single vulnerable function as prompt input for generating patches, which prevents the model from utilizing adequate contextual information and limits its ability to produce accurate patches. (2) Difficulties in extracting effective fix patterns. The substantial semantic differences between various vulnerabilities result in a wide range of fix patterns. Consequently, automatically extracting effective fix patterns tailored to specific vulnerabilities becomes a significant challenge. To address this, we propose PailGen, a novel fix P attern- a ware, i n-context l earning-incorporated vulnerability patch Gen eration approach. PailGen comprises three main modules: hybrid patch retrieval module, fix pattern mining module and in-context learning-incorporated patch generation module. (1) Hybrid patch retrieval module, aims at retrieving the top- \(k\) relevant vulnerability-fix pairs from the existing codebase by combining BM25 and Dense Passage Retriever (DPR) to construct a hybrid patch retriever. (2) Fix pattern mining module, aims at extracting effective fix patterns from the relevant vulnerability-fix pairs by leveraging an automatic fix pattern mining strategy based on Abstract Syntax Tree (AST). Fix patterns are designed to analyze code changes at different levels (e.g., expression level and statement level). (3) In-context learning-incorporated patch generation module, aims at providing comprehensive contextual information for LLMs by integrating the vulnerable code, its AST, the relevant patches and the extracted fix patterns into the prompt input. Overall, PailGen delivers better demonstrations for in-context learning and provides more comprehensive semantic guidance for patch generation, enabling LLMs to effectively address vulnerabilities. We evaluate PailGen on two real-world C/C++ vulnerability datasets. The experimental results demonstrate that PailGen achieves the best performance, outperforming all baseline approaches.

ACM Transactions on Software Engineering and Methodology
Harbin Institute of Technology (CN)
Openalex Percentile: Top 63%
Adversarial Robustness in Machine Learning
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.