My_DiverseVul / README.md
starsofchance's picture
Add dataset card
1e08592 verified
metadata
dataset_info:
  name: DiverseVul
  description: >-
    A comprehensive dataset of vulnerable and non-vulnerable C/C++ source code
    for deep learning-based vulnerability detection, featuring 523,956 functions
    from 933 projects and 155 CWEs.
  citation: |
    @article{chen2023diversevul,
      title={DiverseVul: A New Vulnerable Source Code Dataset for Deep Learning Based Vulnerability Detection},
      author={Chen, Yizheng and Ding, Zhoujie and Alowain, Lamya and Chen, Xinyun and Wagner, David},
      journal={arXiv preprint arXiv:2304.00409v2},
      year={2023}
    }
  homepage: https://github.com/wagner-group/diversevul
  license: Not specified; usage subject to original authors' terms and project licenses
  features:
    - name: project
      type: string
      description: Name of the open-source project the function originates from
    - name: commit_id
      type: string
      nullable: true
      description: Commit ID associated with the function, or null if unavailable
    - name: target
      type: int32
      description: Binary label (0 = non-vulnerable, 1 = vulnerable)
    - name: func
      type: string
      description: Full C/C++ source code of the function
    - name: idx
      type: int32
      description: Unique index of the sample
  splits:
    - name: train
      num_examples: 419404
    - name: validation
      num_examples: 52337
    - name: test
      num_examples: 52215
  task_categories:
    - text-classification
  languages:
    - C
    - C++
  pretty_name: DiverseVul - Vulnerable Source Code Dataset

DiverseVul Dataset Card

Dataset Description

DiverseVul is a comprehensive and meticulously curated dataset of vulnerable and non-vulnerable C/C++ source code, designed to advance deep learning-based vulnerability detection research. Originally introduced by Yizheng Chen, Zhoujie Ding, Lamya Alowain, Xinyun Chen, and David Wagner in their seminal paper, this dataset has been expanded and uploaded to Hugging Face to facilitate broader access and application. It captures real-world software vulnerabilities extracted from vulnerability-fixing commits across a diverse array of open-source projects, making it an invaluable resource for researchers, developers, and security professionals.

Dataset Summary

The version of DiverseVul hosted on Hugging Face represents an enhanced and more complete iteration of the dataset described in the original paper. It contains 523,956 rows of function-level source code samples, split into three predefined sections:

  • Training Set: 419,404 rows
  • Validation Set: 52,337 rows
  • Test Set: 52,215 rows

These samples are derived from 933 unique projects and cover 155 Common Weakness Enumerations (CWEs), including:

  • Number of target0 in training split: 386305
  • Number of target1 in training split: 33099
  • Number of target0 in test_data split: 48072
  • Number of target1 in test_data split: 4143
  • Number of target0 in val_data split: 48202
  • Number of target1 in val_data split: 4135

Citation

This dataset was created by Yizheng Chen, Zhoujie Ding, Lamya Alowain, Xinyun Chen, and David Wagner. If you use DiverseVul in your work, please cite the original paper:

@article{chen2023diversevul,
  title={DiverseVul: A New Vulnerable Source Code Dataset for Deep Learning Based Vulnerability Detection},
  author={Chen, Yizheng and Ding, Zhoujie and Alowain, Lamya and Chen, Xinyun and Wagner, David},
  journal={arXiv preprint arXiv:2304.00409v2},
  year={2023}
}

Note: The version uploaded to Hugging Face is an expanded dataset built upon the original work available at https://github.com/wagner-group/diversevul, with all credit attributed to the original authors.


Dataset Structure

Data Instances

Each row in DiverseVul represents a single C/C++ function extracted from a project, labeled as vulnerable (target: 1) or non-vulnerable (target: 0). The dataset is structured with the following columns:

  • project: The name of the open-source project from which the function originates (e.g., "debian", "bluez", "Chrome").
  • commit_id: The unique identifier of the commit associated with the function. For non-vulnerable functions or cases where commit information is unavailable, this may be None.
  • target: Binary label indicating vulnerability status (0 = non-vulnerable, 1 = vulnerable).
  • func: The full source code of the function as a string, preserving its original syntax and formatting.
  • idx: A unique index assigned to the sample within the dataset.

Example Instances

  • Training Set (Index 0):

    {
      "project": "debian",
      "commit_id": null,
      "target": 0,
      "func": "static guint16 de_ciph_key_seq_num ( tvbuff_t * tvb , proto_tree * tree , packet_info * pinfo _U_ , guint32 offset , guint len _U_ , gchar * add_string _U_ , int string_len _U_ ) {\n guint32 curr_offset , bit_offset ;\n curr_offset = offset ;\n if ( RIGHT_NIBBLE == len ) bit_offset = 4 ;\n else bit_offset = 0 ;\n proto_tree_add_bits_item ( tree , hf_gsm_a_spare_bits , tvb , ( curr_offset << 3 ) + bit_offset , 1 , ENC_BIG_ENDIAN ) ;\n proto_tree_add_bits_item ( tree , hf_gsm_a_key_seq , tvb , ( curr_offset << 3 ) + bit_offset + 1 , 3 , ENC_BIG_ENDIAN ) ;\n curr_offset ++ ;\n return ( curr_offset - offset ) ;\n }",
      "idx": 17792
    }
    

    Description: A non-vulnerable function from the "debian" project, handling bit-level operations for GSM protocol parsing.

  • Test Set (Index 0):

    {
      "project": "bluez",
      "commit_id": "1cd644db8c23a2f530ddb93cebed7dacc5f5721a",
      "target": 1,
      "func": "bool bt_att_cancel(struct bt_att *att, unsigned int id)\n{\n\tconst struct queue_entry *entry;\n\tstruct att_send_op *op;\n\n\tif (!att || !id)\n\t\treturn false;\n\n\t/* Lookuo request on each channel first */\n\tfor (entry = queue_get_entries(att->chans); entry;\n\t\t\t\t\t\tentry = entry->next) {\n\t\tstruct bt_att_chan *chan = entry->data;\n\n\t\tif (bt_att_chan_cancel(chan, id))\n\t\t\treturn true;\n\t}\n\n\top = queue_remove_if(att->req_queue, match_op_id, UINT_TO_PTR(id));\n\tif (op)\n\t\tgoto done;\n\n\top = queue_remove_if(att->ind_queue, match_op_id, UINT_TO_PTR(id));\n\tif (op)\n\t\tgoto done;\n\n\top = queue_remove_if(att->write_queue, match_op_id, UINT_TO_PTR(id));\n\tif (op)\n\t\tgoto done;\n\n\tif (!op)\n\t\treturn false;\n\ndone:\n\tdestroy_att_send_op(op);\n\n\twakeup_writer(att);\n\n\treturn true;\n}",
      "idx": 7502
    }
    

    Description: A vulnerable function from the "bluez" project, tied to a specific commit, managing Bluetooth ATT protocol operations.

  • Validation Set (Index 0):

    {
      "project": "Chrome",
      "commit_id": "d007b8b750851fe1b375c463009ea3b24e5c021d",
      "target": 1,
      "func": " IndexedDBCursor::~IndexedDBCursor() {\n   Close();\n }\n",
      "idx": 10542
    }
    

    Description: A concise, vulnerable destructor from the "Chrome" project, linked to a commit fixing an IndexedDB-related vulnerability.

Data Fields

  • project (string): Identifies the source project, reflecting the dataset’s diversity across 933 projects, including well-known ones like "linux," "Chrome," "debian," and "bluez."
  • commit_id (string or null): Ties the function to a specific vulnerability-fixing commit, providing traceability where available.
  • target (integer): Labels the function’s vulnerability status, enabling binary classification tasks.
  • func (string): Contains the raw C/C++ code, offering rich context for code analysis and model training.
  • idx (integer): A unique identifier for tracking and referencing individual samples.

Source Data

DiverseVul was constructed by crawling security issue websites to identify vulnerability-fixing commits from 933 open-source C/C++ projects. The authors cloned these projects, extracted relevant commits, and parsed C/C++ files to label functions as vulnerable (changed in the commit) or non-vulnerable (unchanged or post-fix). The process involved deduplication using MD5 hashes and mapping vulnerabilities to 155 CWEs via the National Vulnerability Database (NVD) API and manual annotation.

Annotation Process

  • Vulnerable Functions: Functions modified in vulnerability-fixing commits are labeled target: 1. Manual analysis of 50 samples from DiverseVul showed a 60% label accuracy, with errors due to multi-function vulnerabilities or irrelevant changes.
  • Non-Vulnerable Functions: Unchanged functions or post-fix versions are labeled target: 0.
  • CWE Coverage: Approximately 85% of vulnerable functions are mapped to 155 CWE categories, enhancing the dataset’s utility for specific vulnerability type studies.

Projects Covered

The dataset spans a wide range of projects, including but not limited to: - leptonica, mongo, drogon, libuv, ark, exiv2, Bento4, perl5, e2guardian, libheif - pigz, Little-CMS, polarssl, godot, openafs, arangodb, infradead, android_security - qtbase, git, uftpd, linux-uek, xrootd, runc, dosfstools, openmpt, webserver - yast-core, jhead, cJSON, vim, openfortivpn, libgit2, abrt, c-blosc2, libfep - And many more

Uses

What Kind of Projects This Dataset Is Good For

DiverseVul is ideal for:

  • Vulnerability Detection Research: Training and evaluating deep learning models (e.g., LLMs, GNNs) to identify C/C++ vulnerabilities.
  • Software Security Tools: Developing or enhancing static analysis tools and code auditing systems.
  • Educational Purposes: Teaching students about software vulnerabilities, CWEs, and secure coding practices.
  • Generalization Studies: Investigating model performance on unseen projects, a critical challenge in real-world deployment.
  • CWE-Specific Analysis: Studying patterns in specific vulnerability types due to its broad CWE coverage.

How People Can Use the Dataset

  • Machine Learning Training: Use the train/validation/test splits to fine-tune models like CodeT5, NatGen, or custom architectures for binary classification (vulnerable vs. non-vulnerable).
    • Example: Fine-tune a transformer model on the func column with target as the label.
  • Code Analysis: Analyze the func field to extract features (e.g., ASTs, CFGs) for traditional or hybrid vulnerability detection methods.
  • Project Benchmarking: Evaluate model generalization by training on a subset of projects and testing on others, leveraging the project field.
  • CWE Research: Filter samples by CWE (via external mapping) to study specific vulnerability types or improve detection for hard-to-learn CWEs.
  • Data Augmentation: Combine with other datasets (e.g., CVEFixes, BigVul) to increase training volume and diversity.

Limitations

  • Label Noise: Automated labeling from commits introduces errors (e.g., irrelevant changes mislabeled as vulnerable), potentially affecting model performance.
  • C/C++ Focus: Limited to C/C++ code, not applicable to other languages without adaptation.
  • Pretraining Contamination Risk: Some LLMs may have seen code from these projects during pretraining, though this is unlikely to include vulnerability annotations.
  • Whitespace Duplication: Lack of whitespace normalization during deduplication may retain redundant samples.