The product receives input that is expected to specify a quantity (such as size or length), but it does not validate or incorrectly validates that the quantity has the required properties.

Specified quantities include size, length, frequency, price, rate, number of operations, time, and others. Code may rely on specified quantities to allocate resources, perform calculations, control iteration, etc.

Primary

Implementation
Since quantities are often used to affect resource allocation or process financial data, they are often present in many places in the code.

Other
Integrity
Availability
Varies by Context
DoS: Resource Consumption (CPU)
Modify Memory
Read Memory
When the quantity is not properly validated, then attackers can specify malicious quantities to cause excessive resource allocation, trigger unexpected failures, enable buffer overflows, etc.

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.)

Implementation
Input Validation

Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does.
When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue."
Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright.

High

This example demonstrates a shopping interaction in which the user is free to specify the quantity of items to be purchased and a total is calculated.

...public static final double price = 20.00;int quantity = currentUser.getAttribute("quantity");double total = price * quantity;chargeUser(total);...

The user has no control over the price variable, however the code does not prevent a negative value from being specified for quantity. If an attacker were to provide a negative value, then the user would have their account credited instead of debited.

This example asks the user for a height and width of an m X n game board with a maximum dimension of 100 squares.

...#define MAX_DIM 100...
/* board dimensions */

int m,n, error;board_square_t *board;printf("Please specify the board height: \n");error = scanf("%d", &m);if ( EOF == error ){die("No integer passed: Die evil hacker!\n");}printf("Please specify the board width: \n");error = scanf("%d", &n);if ( EOF == error ){die("No integer passed: Die evil hacker!\n");}if ( m > MAX_DIM || n > MAX_DIM ) {die("Value too large: Die evil hacker!\n");}board = (board_square_t*) malloc( m * n * sizeof(board_square_t));...

While this code checks to make sure the user cannot specify large, positive integers and consume too much memory, it does not check for negative values supplied by the user. As a result, an attacker can perform a resource consumption (CWE-400) attack against this program by specifying two, large negative values that will not overflow, resulting in a very large memory allocation (CWE-789) and possibly a system crash. Alternatively, an attacker can provide very large negative values which will cause an integer overflow (CWE-190) and unexpected behavior will follow depending on how the values are treated in the remainder of the program.

The following code is a workflow job written
using YAML. The code attempts to download pull request
artifacts, unzip from the artifact called pr.zip and
extract the value of the file NR into a variable
"pr_number" that will be used later in another job. It
attempts to create a github workflow environment
variable, writing to $GITHUB_ENV. The environment
variable value is retrieved from an external
resource.

name: Deploy Preview
jobs:

deploy:

runs-on: ubuntu-latest
steps:

- name: 'Download artifact'
uses: actions/github-script
with:

script: |

var artifacts = await github.actions.listWorkflowRunArtifacts({

owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},

});
var matchPrArtifact = artifacts.data.artifacts.filter((artifact) => {

return artifact.name == "pr"

})[0];
var downloadPr = await github.actions.downloadArtifact({

owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchPrArtifact.id,
archive_format: 'zip',

});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(downloadPr.data));

- run: |

unzip pr.zip
echo "pr_number=$(cat NR)" >> $GITHUB_ENV

The code does not neutralize the value of the
file NR, e.g. by validating that NR only contains a
number (CWE-1284). The NR file is attacker controlled
because it originates from a pull request that produced
pr.zip.
The attacker could escape the existing
pr_number and create a new variable using a "\n"
(CWE-93) followed by any environment variable to be
added such as:

\nNODE_OPTIONS="--experimental-modules --experiments-loader=data:text/javascript,console.log('injected code');//"

This would result in injecting and running
javascript code (CWE-94) on the workflow runner with
elevated privileges.

The code could be modified to validate that the NR
file only contains a numeric value, or the code could
retrieve the PR number from a more trusted source.

CVE-2025-46687
Chain: Javascript engine code does not perform a length check (CWE-1284) leading to integer overflow (CWE-190) causing allocation of smaller buffer than expected (CWE-131) resulting in a heap-based buffer overflow (CWE-122)
https://www.cve.org/CVERecord?id=CVE-2025-46687

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).
https://www.cve.org/CVERecord?id=CVE-2019-19911

CVE-2008-1440
lack of validation of length field leads to infinite loop
https://www.cve.org/CVERecord?id=CVE-2008-1440

CVE-2008-2374
lack of validation of string length fields allows memory consumption or buffer over-read
https://www.cve.org/CVERecord?id=CVE-2008-2374

Allowed
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

This entry is still under development and will continue to see updates and content improvements.

CWE Content Team
MITRE
2020-06-24
4.1
2020-02-24

CWE Content Team
MITRE
2022-10-13
updated Observed_Examples, Relationships

CWE Content Team
MITRE
2023-04-27
updated Relationships

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes, Relationships

CWE Content Team
MITRE
2025-09-09
4.18
2025-09-09
updated Observed_Examples

CWE Content Team
MITRE
2025-12-11
4.19
2025-12-11
updated Common_Consequences, Demonstrative_Examples, Description, Detection_Factors, Modes_of_Introduction, Observed_Examples, Weakness_Ordinalities