← Latest papers
🤖 AI

LLM-based Vulnerable Code Augmentation: Generate or Refactor?

This paper investigates whether LLM-based data augmentation for vulnerable code is more effective through the generation of new samples or the semantics-preserving refactoring of existing ones, ultimately finding that a hybrid approach best improves the performance of deep learning-based vulnerability classifiers.

Original authors: Dyna Soumhane Ouchebara, Stéphane Dupont

Published 2026-02-11
📖 4 min read☕ Coffee break read

Original authors: Dyna Soumhane Ouchebara, Stéphane Dupont

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

The Problem: The "Rare Disease" Dilemma in Code

Imagine you are training a highly advanced medical AI to detect rare diseases. To do this well, the AI needs to see thousands of examples of each disease. But there’s a problem: some diseases are incredibly common (like the flu), while others are extremely rare. Because you only have a handful of examples for the rare ones, the AI becomes an expert at spotting the flu but remains "blind" to the rare diseases.

In the world of cybersecurity, software vulnerabilities are exactly like those rare diseases. Most code is "healthy" (safe), but certain types of "bugs" (vulnerabilities) are very rare in datasets. Because AI models learn by seeing patterns, if they don't see enough examples of a specific type of bug, they won't know how to catch it when it actually appears in the real world.

The Solution: The "Digital Mimic" Strategy

The researchers in this paper decided to solve this scarcity by using a powerful AI (an LLM called Qwen) to act as a "Digital Mimic." Instead of waiting years to collect more real-world examples, they used the AI to "manufacture" new ones.

They tested two different ways of doing this:

1. The "Improviser" (Generation-based Augmentation)

Think of this like a professional actor who has seen a few clips of a villain. You don't give them the actual villain; you just describe the villain's personality and show them a few clips for inspiration. Then, you say, "Now, go out and create five brand-new villains from scratch!"

  • How it works: The AI looks at a few real examples of a bug and then writes entirely new, original pieces of code that contain that same type of bug.

2. The "Makeover Artist" (Refactoring-based Augmentation)

Think of this like taking an existing photo of a person and using Photoshop to change their hair color, clothes, and background, but keeping their face exactly the same. The person is still the same individual, but the photo looks different.

  • How it works: The AI takes a piece of real, vulnerable code and "refactors" it. It renames variables, adds some useless extra lines of code, or rearranges the logic. The "bug" stays in the exact same spot, but the "look" of the code changes.

The Results: What Happened?

The researchers then took these "fake" (but realistic) examples and fed them to a "student" AI (a classifier called CodeBERT) to see if it got smarter.

  • The "Improviser" (Generation) was fast: It could whip up new code very quickly, but it was a bit hit-or-miss with the "labels" (sometimes the AI thought it created a bug, but it wasn't quite right).
  • The "Makeover Artist" (Refactoring) was slower: It took more time to carefully rewrite the code, but the results were very high quality.
  • The "Hybrid" (The Dream Team): The best results came when they used both methods together. By giving the student AI both brand-new "villains" and "makeovers" of old ones, the AI's ability to detect vulnerabilities jumped significantly—improving by up to 24% in some cases!

The "Aha!" Moment: The Length Factor

The researchers also discovered a "hidden rule" of coding AI: Complexity is the enemy.

They found that the AI is great at catching bugs in short, simple snippets of code, but as the code gets longer and more "wordy," the AI starts to get confused and its accuracy drops. It’s like trying to find a needle in a small box versus finding a needle in a massive haystack.

Summary in a Nutshell

Instead of complaining that there isn't enough "bad code" to train on, these researchers used a smart AI to hallucinate realistic bad code. By mixing brand-new creations with clever rewrites of old ones, they turned a "blind" security AI into a much sharper digital detective.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →