---
title: "CWE-674: Uncontrolled Recursion"
url: https://radicalnotion.ai/cwe/cwe-674
type: cwe
description: "The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-674: Uncontrolled Recursion

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 654
- **Of those, in CISA KEV:** 0
- **New in 2026:** 350
- **CWE catalog version:** 4.21

## Description

The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack.

## Alternate terms

- Stack Exhaustion

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | The uncontrolled recursion is often due to an improper or missing conditional |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory) | Resources including CPU, memory, and stack memory could be rapidly consumed or exhausted, eventually leading to an exit or crash. |
| Confidentiality | Read Application Data | In some cases, an application's interpreter might kill a process or thread that appears to be consuming too many resources, such as with PHP's memory\_limit setting. When the interpreter kills the process/thread, it might report an error containing detailed information such as the application's installation path. |

## Potential mitigations

### Implementation

Ensure that an end condition will be reached under all logic conditions. The end condition may include checking against the depth of recursion and exiting with an error if the recursion goes too deep. The complexity of the end condition contributes to the effectiveness of this action.

Effectiveness: Moderate

### Implementation

Increase the stack size.

Effectiveness: Limited. Increasing the stack size might only be a temporary measure, since the stack typically is still not very large, and it might remain easy for attackers to cause an out-of-stack fault.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

In this example a mistake exists in the code where the exit condition contained in flg is never called. This results in the function calling itself over and over again until the stack is exhausted.

Bad code:

```c
void do_something_recursive (int flg)
{
    ... // Do some real work here, but the value of flg is unmodified
    if (flg) { do_something_recursive (flg); }    // flg is never modified so it is always TRUE - this call will continue until the stack explodes
}
int flag = 1; // Set to TRUE
do_something_recursive (flag);
```

Good code:

```c
void do_something_recursive (int flg)
{
    ... // Do some real work here
    // Modify value of flg on done condition
    if (flg) { do_something_recursive (flg); }    // returns when flg changes to 0
}
int flag = 1; // Set to TRUE
do_something_recursive (flag);
```

Note that the only difference between the Good and Bad examples is that the recursion flag will change value and cause the recursive call to return.

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2007-1285 | Deeply nested arrays trigger stack exhaustion. |
| CVE-2007-3409 | Self-referencing pointers create infinite loop and resultant stack exhaustion. |
| CVE-2016-10707 | Javascript application accidentally changes input in a way that prevents a recursive call from detecting an exit condition. |
| CVE-2016-3627 | An attempt to recover a corrupted XML file infinite recursion protection counter was not always incremented missing the exit condition. |
| CVE-2019-15118 | USB-audio driver's descriptor code parsing allows unlimited recursion leading to stack exhaustion. |

## Real CVEs with this weakness (sample of 12 of 654)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-105042 | Apache Qpid Proton C: Unbounded recursion in parsing AMQP message bodies can lead to crash | critical | 9.8 | - | No | 2026-10-29 |
| CVE-2026-43185 | ksmbd: fix signededness bug in smb\_direct\_prepare\_negotiation() | critical | 9.8 | - | No | 2026-05-06 |
| CVE-2026-25971 | ImageMagick's MSL: Stack overflow in ProcessMSLScript | critical | 9.8 | - | No | 2026-02-24 |
| CVE-2023-51803 | - | critical | 9.8 | - | No | 2024-03-31 |
| CVE-2021-41752 | - | critical | 9.8 | - | No | 2022-04-05 |
| CVE-2018-1000618 | - | critical | 9.8 | - | No | 2018-07-09 |
| CVE-2025-10728 | Uncontrolled recursion in Qt SVG module | critical | 9.4 | - | No | 2025-10-03 |
| CVE-2026-32327 | Apache Portable Runtime Utility: apr-util XML stack recursion crash | critical | 9.1 | - | No | 2026-08-06 |
| CVE-2026-40324 | Hot Chocolate's Utf8GraphQLParser has Stack Overflow via Deeply Nested GraphQL Documents | critical | 9.1 | - | No | 2026-04-17 |
| CVE-2023-2663 | Stack overflow in Xpdf 4.04 due to object loop in PDF page label tree | critical | 9.1 | - | No | 2023-05-11 |
| CVE-2026-121092 | Uncontrolled recursion in SVG | high | 8.8 | - | No | 2026-11-03 |
| CVE-2025-39704 | LoongArch: KVM: Fix stack protector issue in send\_ipi\_data() | high | 8.8 | - | No | 2025-09-05 |

## Related attack patterns (CAPEC)

- [CAPEC-230](https://radicalnotion.ai/capec/capec-230): Serialized Data with Nested Payloads
- [CAPEC-231](https://radicalnotion.ai/capec/capec-231): Oversized Serialized Data Payloads

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-834](https://radicalnotion.ai/cwe/cwe-834) | Excessive Iteration |
| Child | [CWE-776](https://radicalnotion.ai/cwe/cwe-776) | Improper Restriction of Recursive Entity References in DTDs |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| OWASP Top Ten 2004 | Denial of Service | A9 | CWE More Specific |
| Software Fault Patterns | Unrestricted Consumption | SFP13 | - |
| OMG ASCRM | - | ASCRM-CWE-674 | - |

## Frequently asked questions

### What is CWE-674?

The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack.

### What CVEs are caused by CWE-674?

654 recorded CVEs are attributed to CWE-674, including CVE-2026-105042, CVE-2026-43185 and CVE-2026-25971.

### Is CWE-674 part of the OWASP Top 10?

CWE-674 maps to OWASP Top Ten 2004: Denial of Service (A9) in the OWASP security taxonomy.

### How do you prevent CWE-674?

Ensure that an end condition will be reached under all logic conditions. The end condition may include checking against the depth of recursion and exiting with an error if the recursion goes too deep. The complexity of the end condition contributes to the effectiveness of this action.

### How is CWE-674 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-674?

Exploiting CWE-674 can lead to: DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), Read Application Data.

### Is CWE-674 actively exploited?

654 recorded CVEs are caused by CWE-674; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/674.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-674). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
