CWE-789: Memory Allocation with Excessive Size Value
Also known as: Stack Exhaustion
The product allocates memory based on an untrusted, large size value, but it does not ensure that the size is within expected limits, allowing arbitrary amounts of memory to be allocated.
Last updated
Overview
CWE-789 (Memory Allocation with Excessive Size Value) is a variant-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.
Real-world CVEs
190 recorded CVEs are caused by CWE-789 (Memory Allocation with Excessive Size Value). The highest-severity and most recent are shown first. 116 new CWE-789 CVEs have been recorded so far in 2026 (19 in 2025).
- CVE-2023-43632
Freely Allocate Buffer on The Stack With Data From Socket
Critical · CVSS 9.9 · EPSS 43th2023-09-21 - CVE-2023-24201Critical · CVSS 9.8 · EPSS 57th2023-02-06
- CVE-2022-36078High · CVSS 8.8 · EPSS 65th2022-09-02
- CVE-2021-34869High · CVSS 8.8 · EPSS 35th2022-01-25
- CVE-2021-34868High · CVSS 8.8 · EPSS 35th2022-01-25
- CVE-2026-81693
openssl_encrypt before 1.4.9 Denial of Service via QR total field
High · CVSS 8.7 · EPSS 27th2026-08-27 - CVE-2026-81692
openssl_encrypt before 1.4.9 Denial of Service via STREAMINFO
High · CVSS 8.7 · EPSS 27th2026-08-27 - CVE-2026-75935
Memory-amplification denial of service via declared-length preallocation in Amazon ion-java
High · CVSS 8.7 · EPSS 37th2026-08-18 - CVE-2026-69219
RabbitMQ Java client ValueReader: Oversized LongString/bytes length triggers OOM via unchecked allocation
High · CVSS 8.7 · EPSS 35th2026-08-18 - CVE-2026-66733
Sonic 3 A.I.R. Unbounded Memory Allocation DoS via ReceivedPacketCache
High · CVSS 8.7 · EPSS 57th2026-08-06 - CVE-2026-58067High · CVSS 8.7 · EPSS 32th2026-08-04
- CVE-2026-12852
MLS wire decoder allocates attacker-declared opaque length before bounds check
High · CVSS 8.7 · EPSS 23th2026-08-03
Showing 12 of 190 recorded CWE-789 CVEs. Track new ones as they are published and get AI-written analysis and fixes.
Monitor CWE-789 vulnerabilitiesCommon consequences
What can happen when CWE-789 is exploited.
DoS: Resource Consumption (Memory)
Affects: Availability
Not controlling memory allocation can result in a request for too much system memory, possibly leading to a crash of the application due to out-of-memory conditions, or the consumption of a large amount of memory on the system.
How it happens
When it is introduced
Typically introduced during these phases of the software lifecycle.
Applies to
Languages
How to prevent it
Practical mitigations for CWE-789, grouped by where in the lifecycle they apply.
Perform adequate input validation against any value that influences the amount of memory that is allocated. Define an appropriate strategy for handling requests that exceed the limit, and consider supporting a configuration option so that the administrator can extend the amount of memory to be used if necessary.
Run your program using system-provided resource limits for memory. This might still cause the program to crash or exit, but the impact to the rest of the system will be minimized.
How to detect it
Fuzzing
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
Effectiveness: High
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
Automated Dynamic Analysis
Use tools that are integrated during compilation to insert runtime error-checking mechanisms related to memory safety errors, such as AddressSanitizer (ASan) for C/C++ [REF-1518].
Effectiveness: Moderate
Code examples
Illustrative examples from MITRE showing how the weakness appears in code.
Consider the following code, which accepts an untrusted size value and allocates a buffer to contain a string of the given size.
Vulnerable example
/* ignore integer overflow (CWE-190) for this example */
unsigned int size = GetUntrustedInt();Consider the following code, which accepts an untrusted size value and uses the size as an initial capacity for a HashMap.
Vulnerable example
unsigned int size = GetUntrustedInt();The HashMap constructor will verify that the initial capacity is not negative, however there is no check in place to verify that sufficient memory is present. If the attacker provides a large enough value, the application will run into an OutOfMemoryError.
This code performs a stack allocation based on a length calculation.
Vulnerable example
int a = 5, b = 6;This example shows a typical attempt to parse a string with an error resulting from a difference in assumptions between the caller to a function and the function's action.
The buffer length ends up being -1, resulting in a blown out stack. The space character after the colon is included in the function calculation, but not in the caller's calculation. This, unfortunately, is not usually so obvious but exists in an obtuse series of calculations.
The following code obtains an untrusted number that is used as an index into an array of messages.
Vulnerable example
my $num = GetUntrustedNumber();This example shows a typical attempt to parse a string with an error resulting from a difference in assumptions between the caller to a function and the function's action. The buffer length ends up being -1 resulting in a blown out stack. The space character after the colon is included in the function calculation, but not in the caller's calculation. This, unfortunately, is not usually so obvious but exists in an obtuse series of calculations.
Illustrative examples
Real CVEs that MITRE cites as examples of this weakness.
- CVE-2023-2253 — Query capability for API endpoint allows a large value for number of records to return, leading to allocation of a large array
- CVE-2019-19911 — Chain: Python library does not limit the resources used to process images that specify a very large number of bands (CWE-1284), leading to excessive memory consumption (CWE-789) or an integer overflow (CWE-190).
- CVE-2010-3701 — program uses ::alloca() for encoding messages, but large messages trigger segfault
- CVE-2008-1708 — memory consumption and daemon exit by specifying a large value in a length field
- CVE-2008-0977 — large value in a length field leads to memory consumption and crash when no more memory is available
- CVE-2006-3791 — large key size in game program triggers crash when a resizing function cannot allocate enough memory
- CVE-2004-2589 — large Content-Length HTTP header value triggers application crash in instant messaging application due to failure in memory allocation
Terminology & mappings
Alternate terms
- Stack Exhaustion
- When a weakness allocates excessive memory on the stack, it is often described as "stack exhaustion," which is a technical impact of the weakness. This technical impact is often encountered as a consequence of CWE-789 and/or CWE-1325.
Mapped taxonomies
- WASC: SOAP Array Abuse (35)
- CERT C Secure Coding: Allocate sufficient memory for an object (MEM35-C) — Imprecise fit
- SEI CERT Perl Coding Standard: Validate any integer that is used as an array index (IDS32-PL) — Imprecise fit
- OMG ASCSM (ASCSM-CWE-789)
Frequently asked questions
Common questions about CWE-789.
- What is CWE-789?
- The product allocates memory based on an untrusted, large size value, but it does not ensure that the size is within expected limits, allowing arbitrary amounts of memory to be allocated.
- What CVEs are caused by CWE-789?
- 190 recorded CVEs are attributed to CWE-789, including CVE-2023-43632, CVE-2023-24201, CVE-2022-36078.
- How do you prevent CWE-789?
- Perform adequate input validation against any value that influences the amount of memory that is allocated. Define an appropriate strategy for handling requests that exceed the limit, and consider supporting a configuration option so that the administrator can extend the amount of memory to be used if necessary.
- How is CWE-789 detected?
- Fuzzing: Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
- What are the consequences of CWE-789?
- Exploiting CWE-789 can lead to: DoS: Resource Consumption (Memory).
- Is CWE-789 actively exploited?
- 190 recorded CVEs are caused by CWE-789; none are currently in CISA's KEV catalog of actively exploited flaws.
References
- MITRE CWE definition (CWE-789) (opens in a new tab)
- CWE-789 vulnerabilities on NVD (opens in a new tab)
- Learn: What is a CWE?
Weakness data is sourced from the MITRE CWE catalog (v4.20). CVE associations are aggregated and kept current by RadicalNotion.AI.
Stay ahead of CWE-789
Get alerted the moment a new CWE-789 vulnerability affects your stack, with AI-written analysis, severity context, and remediation guidance.