How secure is AI-generated code: a large-scale comparison of large language models
Open accessThe DOI matches its Crossref record; 23 of the 23 references it cites were found in a registry or an index.
Abstract
This study compares state-of-the-art Large Language Models (LLMs) on their tendency to generate vulnerabilities when writing C programs using a neutral zero-shot prompt. Tihanyi et al. introduced the FormAI dataset at PROMISE ’23, featuring 112,000 C programs generated by GPT-3.5-turbo, with over 51.24% identified as vulnerable. We extended that research with a large-scale study involving 9 state-of-the-art models such as OpenAI’s GPT-4o-mini, Google’s Gemini Pro 1.0, TII’s 180 billion-parameter Falcon, Meta’s 13 billion-parameter Code Llama, and several other compact models. Additionally, we introduce the FormAI-v2 dataset, which comprises 331 000 compilable C programs generated by these LLMs. Each program in the dataset is labeled based on the vulnerabilities detected in its source code through formal verification, using the Efficient SMT-based Context-Bounded Model Checker (ESBMC). This technique minimizes false positives by providing a counterexample for the specific vulnerability and reduces false negatives by thoroughly completing the verification process. Our study reveals that at least 62.07% of the generated programs are vulnerable. The differences between the models are minor, as they all show similar coding errors with slight variations. Our research highlights that while LLMs offer promising capabilities for code generation, deploying their output in a production environment requires proper risk assessment and validation.
Overview
The claims and statistics of this paper haven’t been checked yet.
Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.
Integrity signals
Registry
Cites
Statistics
Verification
Claims the paper makes
The claims and statistics of this paper haven’t been checked yet.
Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.
Self-check
Percentages, sums and reported differences re-computed from the paper’s own numbers.
The self-check needs the paper’s full text.
Citations
Cites
McCabe, T. J. (1976) · IEEE Transactions on Software Engineering · doi:10.1109/tse.1976.233837 · Cited by 6,059
Large Language Models for Software Engineering: A Systematic Literature Review
Hou, X., Zhao, Y., Liu, Y., Yang, Z., Wang, K., Li, L., Luo, X., Lo, D., Grundy, J., & Wang, H. (2024) · ACM Transactions on Software Engineering and Methodology · doi:10.1145/3695988 · Cited by 1,029
A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT
White, J., Fu, Q., Hays, S., Sandborn, M., Olea, C., Gilbert, H., Elnashar, A., Spencer-Smith, J., & Schmidt, D. C. (2023) · arXiv · doi:10.48550/arxiv.2302.11382 · Cited by 838
Software Testing With Large Language Models: Survey, Landscape, and Vision
Wang, J., Huang, Y., Chen, C., Liu, Z., Wang, S., & Wang, Q. (2024) · IEEE Transactions on Software Engineering · doi:10.1109/tse.2024.3368208 · Cited by 573 · cited 2×
“…code for SE are rapidly emerging, but the main focus mostly often functional correctness, omitting important security aspects (White et al. 2023; Yao et al. 2024; Wei et al. 2022), or reliability (Tihanyi et al. 2024; Mirzadeh et al. 2024; Honarvar et al. 2023; Wang et al. 2024; Liang et al. 2024).”
A systematic evaluation of large language models of code
Xu, F. F., Alon, U., Neubig, G., & Hellendoorn, V. J. (2022) · Proceedings of the 6th ACM SIGPLAN International Symposium on Machine Programming · doi:10.1145/3520312.3534862 · Cited by 540
CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generation
Lu, S., Guo, D., Ren, S., Huang, J., Svyatkovskiy, A., Blanco, A., Clement, C., Drain, D., Jiang, D., Tang, D., et al. (2021) · arXiv · doi:10.48550/arxiv.2102.04664 · Cited by 536
Asleep at the Keyboard? Assessing the Security of GitHub Copilot’s Code Contributions
Pearce, H., Ahmad, B., Tan, B., Dolan-Gavitt, B., & Karri, R. (2022) · 2022 IEEE Symposium on Security and Privacy (SP) · doi:10.1109/sp46214.2022.9833571 · Cited by 476
Automated Program Repair in the Era of Large Pre-trained Language Models
Xia, C. S., Wei, Y., & Zhang, L. (2023) · 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE) · doi:10.1109/icse48619.2023.00129 · Cited by 433
Do Users Write More Insecure Code with AI Assistants?
Perry, N., Srivastava, M., Kumar, D., & Boneh, D. (2023) · Proceedings of the 2023 ACM SIGSAC Conference on Computer and Communications Security · doi:10.1145/3576915.3623157 · Cited by 259
Automated Repair of Programs from Large Language Models
Fan, Z., Gao, X., Mirchev, M., Roychoudhury, A., & Tan, S. H. (2023) · 2023 IEEE/ACM 45th International Conference on Software Engineering (ICSE) · doi:10.1109/icse48619.2023.00128 · Cited by 256
InferFix: End-to-End Program Repair with LLMs
Jin, M., Shahriar, S., Tufano, M., Shi, X., Lu, S., Sundaresan, N., & Svyatkovskiy, A. (2023) · Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering · doi:10.1145/3611643.3613892 · Cited by 191 · cited 1×
“…to be an effective method (Cao et al. 2023; Deligiannis et al. 2023; Fan et al. 2023; Gao et al. 2023; Huang et al. 2023; Islam and Najafirad 2024; Jin et al. 2023; Lajkó et al. 2022; Paul et al. 2023; Peng et al. 2024; Tian et al. 2021; Wei et al. 2023; Widjojo and Treude 2023; Xia et al.…”
Large Language Models for Test-Free Fault Localization
Yang, A. Z. H., Le Goues, C., Martins, R., & Hellendoorn, V. (2024) · Proceedings of the IEEE/ACM 46th International Conference on Software Engineering · doi:10.1145/3597503.3623342 · Cited by 144 · cited 1×
“Despite their potential (Hao et al. 2023; Yang et al. 2024; Quan et al. 2023; Sun et al. 2023; Tian et al. 2023; Wang et al. 2023; Zhang et al. 2023), LLMs, on their own face limitations such as a lack of understanding of code semantics and difficulty in handling highly domain-specific knowledge (Wu…”
How Secure is Code Generated by ChatGPT?
Khoury, R., Avila, A. R., Brunelle, J., & Camara, B. M. (2023) · 2023 IEEE International Conference on Systems, Man, and Cybernetics (SMC) · doi:10.1109/smc53992.2023.10394237 · Cited by 141
(2023) · doi:10.1109/sp46215.2023.10179324 · Cited by 131
Wei, Y., Xia, C. S., & Zhang, L. (2023) · Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering · doi:10.1145/3611643.3616271 · Cited by 115 · cited 1×
“…et al. 2023; Fan et al. 2023; Gao et al. 2023; Huang et al. 2023; Islam and Najafirad 2024; Jin et al. 2023; Lajkó et al. 2022; Paul et al. 2023; Peng et al. 2024; Tian et al. 2021; Wei et al. 2023; Widjojo and Treude 2023; Xia et al. 2022; Xia and Zhang 2023; Zhang et al. 2024, 2023a,b).”
Large Language Models for Software Engineering: A Systematic Literature Review
Hou, X., Zhao, Y., Liu, Y., Yang, Z., Wang, K., Li, L., Luo, X., Lo, D., Grundy, J., & Wang, H. (2023) · arXiv · doi:10.48550/arxiv.2308.10620 · Cited by 114 · cited 1×
“In a comprehensive literature review, Hou et al. (2023) examined LLMs’ application, effects,andpossiblelimitationsonSE.”
Finetuning Large Language Models for Vulnerability Detection
Shestov, A., Levichev, R., Mussabayev, R., Maslov, E., Cheshkov, A., & Zadorozhny, P. (2024) · arXiv · doi:10.48550/arxiv.2401.17010 · Cited by 93
Chat Generative Pre-trained Transformer: why we should embrace this technology
Chavez, M. R., Butler, T. S., Rekawek, P., Heo, H., & Kinzler, W. L. (2023) · American Journal of Obstetrics and Gynecology · doi:10.1016/j.ajog.2023.03.010 · Cited by 83 · cited 1×
“Research related to program synthesis using Generative Pre-trained Transformers (GPT) (Chavez et al. 2023) is gaining significant traction, where initial studiesindicatethatGPTmodelscangeneratesyntacticallycorrectyetvulnerablecode(Char-alambous et al. 2023).”
Understanding the Effectiveness of Large Language Models in Detecting Security Vulnerabilities
Khare, A., Dutta, S., Li, Z., Solko-Breslin, A., Alur, R., & Naik, M. (2023) · arXiv · doi:10.48550/arxiv.2311.16169 · Cited by 64
LLMs in Web Development: Evaluating LLM-Generated PHP Code Unveiling Vulnerabilities and Limitations
Tóth, R., Bisztray, T., & Erdődi, L. (2024) · Lecture Notes in Computer Science · doi:10.1007/978-3-031-68738-9_34 · Cited by 34
Self-citationAgentCoder: Multi-Agent-based Code Generation with Iterative Testing and Optimisation
Huang, D., Zhang, J. M., Luck, M., Bu, Q., Qing, Y., & Cui, H. (2023) · arXiv · doi:10.48550/arxiv.2312.13010 · Cited by 34
Foundational Challenges in Assuring Alignment and Safety of Large Language Models
Anwar, U., Saparov, A., Rando, J., Paleka, D., Turpin, M., Hase, P., Lubana, E. S., Jenner, E., Casper, S., Sourbut, O., et al. (2024) · arXiv · doi:10.48550/arxiv.2404.09932 · Cited by 19
Do Users Write More Insecure Code with AI Assistants?
Perry, N., Srivastava, M., Kumar, D., & Boneh, D. (2022) · arXiv · cited 2×
“AstudyconductedatStanfordUniversitysuggeststhatsoftwareengineersassistedby Ope-nAI’s codex-davinci-002 model were at a higher risk of introducing security flaws into their code (Perry et al. 2023).”
Cited by
When LLMs meet cybersecurity: a systematic literature review
Zhang, J., Bu, H., Wen, H., Liu, Y., Fei, H., Xi, R., Li, L., Yang, Y., Zhu, H., & Meng, D. (2025) · Cybersecurity · doi:10.1186/s42400-025-00361-w · Cited by 383
Yigit, Y., Ferrag, M. A., Ghanem, M. C., Sarker, I. H., Maglaras, L. A., Chrysoulas, C., Moradpoor, N., Tihanyi, N., & Janicke, H. (2025) · Sensors · doi:10.3390/s25061666 · Cited by 69
“By establishing clear boundaries between human controllers and AI agents, maintaining data integrity, and adhering to industry regulations, enterprises can confidently deploy Agentic AI to build more resilient and future-proof infrastructures [136,137].”
Self-citationHelping LLMs Improve Code Generation Using Feedback from Testing and Static Analysis
Dolcetti, G., Arceri, V., Iotti, E., Maffeis, S., Cortesi, A., & Zaffanella, E. (2024) · arXiv · doi:10.48550/arxiv.2412.14841 · Cited by 8
Helping LLMs improve code generation using feedback from testing and static analysis
Dolcetti, G., Arceri, V., Iotti, E., Maffeis, S., Cortesi, A., & Zaffanella, E. (2026) · Discover Artificial Intelligence · doi:10.1007/s44163-026-01009-5 · Cited by 8
A, N., & V, S. (2026) · Software Testing, Verification and Reliability · doi:10.1002/stvr.70021
Metadata
- Authors
- Tihanyi, N., Bisztray, T., Ferrag, M. A., Jain, R., & Cordeiro, L. C.
- Venue
- Empirical Software Engineering
- Published
- 2024-12-21
- Volume
- 30
- Issue
- 2
- ISSN
- 1382-3256 (ISSN-L)
- 1573-7616
- OpenAlex
- W4396820575
- Cited by
- 51
- References
- 23
- FWCI
- 19.52
- Type
- journal article
- Language
- en
- Open access
- green
About these checks
Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.
Statistics and arithmetic are recomputed, not judged.
Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.
What counts as a claim ›How we measure confidence ›How we check this ›
Are you an author, or do you see a problem with this page? Request a review
Data sources
Bibliographic data: Semantic Scholar, OpenAlex, Crossref.
Contains information from the Semantic Scholar Academic Graph Datasets, made available under the ODC Attribution License (ODC-BY 1.0).
Semantic Scholar’s data is described in: Kinney, R., et al. (2023). The Semantic Scholar Open Data Platform. arXiv:2301.10140.