CWE-674: Uncontrolled Recursion
Also known as: Stack Exhaustion
The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack.
Last updated
Also known as: Stack Exhaustion
The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack.
Last updated
CWE-674 (Uncontrolled Recursion) is a class-level software weakness catalogued by MITRE in the Common Weakness Enumeration (CWE). It describes a recurring type of mistake that can lead to exploitable security vulnerabilities.
661 recorded CVEs are caused by CWE-674 (Uncontrolled Recursion). The highest-severity and most recent are shown first. 357 new CWE-674 CVEs have been recorded so far in 2026 (60 in 2025).
Apache Qpid Proton C: Unbounded recursion in parsing AMQP message bodies can lead to crash
ksmbd: fix signededness bug in smb_direct_prepare_negotiation()
ImageMagick's MSL: Stack overflow in ProcessMSLScript
Uncontrolled recursion in Qt SVG module
Apache Portable Runtime Utility: apr-util XML stack recursion crash
Hot Chocolate's Utf8GraphQLParser has Stack Overflow via Deeply Nested GraphQL Documents
Stack overflow in Xpdf 4.04 due to object loop in PDF page label tree
Uncontrolled recursion in SVG
LoongArch: KVM: Fix stack protector issue in send_ipi_data()
Showing 12 of 661 recorded CWE-674 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsWhat can happen when CWE-674 is exploited.
DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory)
Affects: Availability
Resources including CPU, memory, and stack memory could be rapidly consumed or exhausted, eventually leading to an exit or crash.
Read Application Data
Affects: Confidentiality
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.
Typically introduced during these phases of the software lifecycle.
Practical mitigations for CWE-674, grouped by where in the lifecycle they apply.
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
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.
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
MITRE examples of the weakness in code.
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.
Vulnerable example
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);Safe example
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.
Real CVEs that MITRE cites as examples of this weakness.
CAPEC attack patterns that exploit this weakness.
Common questions about CWE-674.
Weakness data is sourced from the MITRE CWE catalog (v4.21). CVE associations are aggregated and kept current by RadicalNotion.AI.
Get an alert when a new CWE-674 CVE affects your products, with AI-written analysis and remediation steps.