CWE-789: Memory Allocation with Excessive Size Value
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
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.
常见后果
影响范围: Availability
技术影响: DoS: Resource Consumption (Memory)
说明: 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.
潜在缓解措施
阶段: Implementation Architecture and Design
描述: 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.
阶段: Operation
描述: 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.
检测方法
方法: 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.
有效性: 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.)
有效性: High
观察示例
参考: 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
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| WASC | 35 | SOAP Array Abuse | - |
| CERT C Secure Coding | MEM35-C | Allocate sufficient memory for an object | Imprecise |
| SEI CERT Perl Coding Standard | IDS32-PL | Validate any integer that is used as an array index | Imprecise |
| OMG ASCSM | ASCSM-CWE-789 | - |