Dataset Viewer
Auto-converted to Parquet Duplicate
conversations
listlengths
2
2
source
stringclasses
1 value
score
float64
4.8
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic u32 apic_get_tmcct(struct kvm_lapic *apic)\n{\n\tktime_t remaining;...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nbool btd_le_connect_before_pairing(void)\n{\n\tif (MGMT_VERSION(mgmt_versi...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstd::string ExpandFilePath(const std::string &filepath, void *) {\n#ifdef ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\npci_emul_alloc_pbar(struct pci_vdev *pdi, int idx, uint64_t hostbase,\n\t\...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nTEST_F(GrpcHealthCheckerImplTest, GoAwayErrorProbeInProgress) {\n // Fail...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic void jpc_undo_roi(jas_matrix_t *x, int roishift, int bgshift, int n...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nlong long AudioTrack::GetChannels() const { return m_channels; }\n```" }...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nxmlParseCheckTransition(xmlParserCtxtPtr ctxt, const char *chunk, int size...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nint git_delta_apply(\n\tvoid **out,\n\tsize_t *out_len,\n\tconst unsigned ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int route4_change(struct net *net, struct sk_buff *in_skb,\n\t\t\t ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nint virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int usbdev_release(struct inode *inode, struct file *file)\n{\n\tst...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nevdev_accel_config_set_speed(struct libinput_device *device, double speed)...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nread_layer_block (FILE *f,\n gint image_ID,\n ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nHttp::Stream::getNextRangeOffset() const\n{\n debugs (33, 5, \"range: \...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nint h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int selinux_sb_remount(struct super_block *sb, void *mnt_opts)\n{\n...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nint ares_parse_a_reply(const unsigned char *abuf, int alen,\n ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nfm_mgr_config_mgr_connect\r\n(\r\n\tfm_config_conx_hdl\t*hdl, \r\n\tfm_mgr...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int l2cap_disconn_ind(struct hci_conn *hcon)\n{\n\tstruct l2cap_con...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, c...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nElf64_Sym const *PackLinuxElf64::elf_lookup(char const *name) const\n{\n ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic inline int compat_copy_match_from_user(struct ipt_entry_match *m,\n...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nload_xwd_f2_d24_b32 (const gchar *filename,\n FILE...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nTPM2B_ID_OBJECT_Marshal(TPM2B_ID_OBJECT *source, BYTE **buffer, INT32 *siz...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int nested_svm_intercept_ioio(struct vcpu_svm *svm)\n{\n\tunsigned ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nvoid perf_event_enable(struct perf_event *event)\n{\n\tstruct perf_event_c...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic inline void ModulateHSL(const double percent_hue,\n const double p...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nint sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sock...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int pgpPrtSigParams(pgpTag tag, uint8_t pubkey_algo,\n\t\tconst uin...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int drbg_hash_update(struct drbg_state *drbg, struct list_head *see...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nItem *Item_func_not_all::neg_transformer(THD *thd)\n{\n /* \"NOT (e $cmp$...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nint ff_jpeg2000_init_component(Jpeg2000Component *comp,\n ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nTEE_Result tee_mmu_check_access_rights(const struct user_ta_ctx *utc,\n\t\...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic char *print_value( cJSON *item, int depth, int fmt )\n{\n\tchar *ou...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nint cil_build_ast(struct cil_db *db, struct cil_tree_node *parse_tree, str...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic struct pending_op *send_read(struct btd_device *device,\n\t\t\t\t\t...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int ax25_recvmsg(struct kiocb *iocb, struct socket *sock,\n\tstruct...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nStatus OplogApplicationChecks::checkAuthForCommand(OperationContext* opCtx...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nvoid mnt_set_expiry(struct vfsmount *mnt, struct list_head *expiry_list)\n...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nselDisplayInPix(SEL *sel,\n l_int32 size,\n ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic int ca8210_probe(struct spi_device *spi_device)\n{\n\tstruct ca8210...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nvoid luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {\n const TVa...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic void user_init(struct hfi1_ctxtdata *uctxt)\n{\n\tunsigned int rcvc...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nQPDF_Stream::pipeStreamData(Pipeline* pipeline,\n ...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nstatic struct inode *alloc_inode(struct super_block *sb)\n{\n\tstruct inod...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\nReturns TRUE if the alrogithm is a block algorithms */\nPHP_FUNCTION(mcryp...
code_vulnerability_cwe
4.8
[ { "from": "human", "value": "Analyze the following code snippet and identify any security vulnerabilities. Provide a detailed explanation of the vulnerability type, its severity, potential impact, and the CWE classification.\n\n```c\n}\n\nvoid dump_hevc_track_info(GF_ISOFile *file, u32 trackNum, GF_HEVCConf...
code_vulnerability_cwe
4.8
End of preview. Expand in Data Studio

Code Vulnerability Balanced β€” CWE-Enriched Conversation Dataset

πŸ“Œ Overview

This dataset is a balanced and shuffled version of ChamaraVishwajithRajapaksha/Code-Vulnerability-FineTune, which itself was derived from the original ChamaraVishwajithRajapaksha/Code_Vulnerability_Dataset (330k rows, sourced from DiverseVul + MITRE CWE enrichment).

The original fine-tuning dataset was imbalanced β€” the number of Vulnerable and Safe samples were not equal β€” and the samples were not shuffled. This dataset addresses both issues:

  • βœ… Balanced β€” Equal number of Vulnerable and Safe (patched) samples
  • βœ… Shuffled β€” Samples are randomly shuffled to prevent ordering bias during training
  • βœ… ShareGPT / FineTome format β€” Ready for fine-tuning with Unsloth, TRL, and similar frameworks

🎯 Use Cases

  • Fine-tuning LLMs for security code review
  • Training vulnerability detection models
  • Building code-aware security assistants
  • Research in automated static analysis and secure coding

πŸ“Š Dataset Statistics

Property Value
Source Dataset ChamaraVishwajithRajapaksha/Code-Vulnerability-FineTune
Balancing Strategy Undersample majority class to match minority class
Shuffled Yes (random seed 42)
Format ShareGPT (conversations)
Languages C, C++
Splits train (90%) Β· test (10%)
License MIT

πŸ”„ What Changed From the Source Dataset

Change Description
Balancing The source dataset had an unequal number of Vulnerable vs Safe samples. This dataset undersamples the majority class so both are equal in count.
Shuffling All rows are randomly shuffled (seed 42) before splitting, preventing the model from learning ordering patterns.
Same format The ShareGPT conversation structure is preserved exactly as in the source dataset.

πŸ—‚οΈ Data Format

Each row follows the ShareGPT conversation format with two turns:

{
  "conversations": [
    {
      "from": "human",
      "value": "Analyze the following code snippet and identify any security vulnerabilities...\n\n```c\n<source code>\n```"
    },
    {
      "from": "gpt",
      "value": "## Security Vulnerability Analysis\n\n⚠️ This code sample is marked as **Vulnerable**.\n\n### πŸ” Vulnerability Classification\n- **CWE ID**: CWE-787\n- **Type**: Out-of-bounds Write\n- **Severity**: High\n..."
    }
  ],
  "source": "code_vulnerability_cwe",
  "score": 4.8
}

Fields

Field Type Description
conversations list List of 2 conversation turns
conversations[0].from str Always "human"
conversations[0].value str Instruction + C/C++ code block
conversations[1].from str Always "gpt"
conversations[1].value str Structured vulnerability analysis
source str Always "code_vulnerability_cwe"
score float Quality score (4.8)

πŸ”„ Preprocessing Pipeline

Step 1 β€” Load

Load the source dataset from Hugging Face Hub (ChamaraVishwajithRajapaksha/Code-Vulnerability-FineTune).

Step 2 β€” Separate by Label

Split all rows into two groups:

  • Vulnerable samples
  • Safe (patched) samples

Step 3 β€” Balance

Undersample the larger group so that both groups have an equal number of rows, resulting in a 50/50 class distribution.

Step 4 β€” Shuffle

Combine the two balanced groups and shuffle the entire dataset with a fixed random seed (42) for reproducibility.

Step 5 β€” Split & Push

  • 90% / 10% train-test split (random seed 42)
  • Pushed to Hugging Face Hub in Parquet format

πŸ“‹ CWE Categories Covered

The dataset covers a wide range of Common Weakness Enumeration types including:

CWE ID Vulnerability Type
CWE-787 Out-of-bounds Write
CWE-416 Use After Free
CWE-125 Out-of-bounds Read
CWE-476 NULL Pointer Dereference
CWE-119 Improper Buffer Restriction
CWE-284 Improper Access Control
CWE-20 Improper Input Validation
CWE-78 OS Command Injection
CWE-327 Broken Cryptographic Algorithm
CWE-835 Infinite Loop
CWE-122 Heap-based Buffer Overflow
CWE-362 Race Condition
CWE-22 Path Traversal
CWE-287 Improper Authentication
CWE-319 Cleartext Transmission
... 30+ more CWE types

πŸ§ͺ Sample Example

Human Turn

Analyze the following code snippet and identify any security vulnerabilities.
Provide a detailed explanation of the vulnerability type, its severity,
potential impact, and the CWE classification.

static boolean ReadICCProfile(j_decompress_ptr jpeg_info) {
  char magick[12];
  ErrorManager *error_manager;
  ExceptionInfo *exception;
  Image *image;
  ...
}

Assistant Turn

## Security Vulnerability Analysis

⚠️ This code sample is marked as **Vulnerable**.

### πŸ” Vulnerability Classification
- **CWE ID**: CWE-416
- **Type**: Use After Free
- **Severity**: High
- **Category**: Memory Corruption
- **Affected Languages**: C, C++

### πŸ“‹ Description
The product reuses or references memory after it has been freed. At some point
afterward, the memory may be allocated again and saved in another pointer, while
the original pointer references a location somewhere within the new allocation.

### πŸ’₯ Potential Impact
  - Execute Unauthorized Code or Commands
  - Read Memory
  - Modify Memory
  - DoS: Crash, Exit, or Restart

### πŸ›‘οΈ Recommendation
Review the code for Use After Free patterns. Ensure proper bounds checking,
input validation, and memory management practices are applied as recommended
by the CWE guidelines for CWE-416.

πŸš€ Usage

Load with πŸ€— Datasets

from datasets import load_dataset

dataset = load_dataset("ChamaraVishwajithRajapaksha/Code-Vulnerability-Balanced")
print(dataset)
# DatasetDict({
#     train: Dataset({features: ['conversations', 'source', 'score'], num_rows: ...}),
#     test:  Dataset({features: ['conversations', 'source', 'score'], num_rows: ...})
# })

Access a Sample

sample = dataset['train'][0]

# Print the human question (code to analyze)
print(sample['conversations'][0]['value'])

# Print the assistant answer (vulnerability analysis)
print(sample['conversations'][1]['value'])

Fine-tuning with Unsloth / TRL

from trl import SFTTrainer
from unsloth import FastLanguageModel

# The dataset is already in ShareGPT format β€” compatible with
# most fine-tuning frameworks that support conversation datasets.
trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    train_dataset=dataset['train'],
    dataset_text_field="conversations",  # adjust per framework
    ...
)

πŸ“ Dataset Lineage

bstee615/diversevul
    └──> ChamaraVishwajithRajapaksha/Code_Vulnerability_Dataset
              (330k rows, CWE-enriched via MITRE API)
         └──> ChamaraVishwajithRajapaksha/Code-Vulnerability-FineTune
                   (ShareGPT format, unbalanced, unshuffled)
              └──> ChamaraVishwajithRajapaksha/Code-Vulnerability-Balanced
                        (balanced + shuffled β€” this dataset)

⚠️ Limitations

  • Code samples are primarily in C and C++ β€” limited coverage of other languages
  • Balancing is achieved by undersampling the majority class, so total row count is reduced compared to the source dataset
  • The Safe samples represent patched/fixed versions, not inherently safe code β€” context matters
  • CWE details describe the class of vulnerability, not a precise analysis of each individual function
  • This dataset is intended for research and educational purposes

πŸ“œ License

This dataset is released under the MIT License, consistent with the source dataset license.


πŸ™ Citation

If you use this dataset in your research, please cite the original source and this dataset:

@dataset{code_vulnerability_balanced,
  title        = {Code Vulnerability Balanced: CWE-Enriched Conversation Dataset},
  author       = {ChamaraVishwajithRajapaksha},
  year         = {2025},
  publisher    = {Hugging Face},
  url          = {https://huggingface.co/datasets/ChamaraVishwajithRajapaksha/Code-Vulnerability-Balanced},
  note         = {Balanced and shuffled version of Code-Vulnerability-FineTune, in ShareGPT format}
}

πŸ”— Related Resources

Downloads last month
-