---
title: "CWE-1284: Improper Validation of Specified Quantity in Input"
url: https://radicalnotion.ai/cwe/cwe-1284
type: cwe
description: "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."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-1284: Improper Validation of Specified Quantity in Input

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 415
- **Of those, in CISA KEV:** 1
- **New in 2026:** 229
- **CWE catalog version:** 4.21

## Description

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.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | Code may rely on specified quantities to allocate resources, perform calculations, control iteration, etc. Since quantities are often used to affect resource allocation or process financial data, they are often present in many places in the code. |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| 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. |

## Potential mitigations

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

Effectiveness: High

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

## Demonstrative examples

### Example 1

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.

Bad code:

```java
...
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.

### Example 2

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

Bad code:

```c
...
#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.

### Example 3

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.

Bad code:

```other
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
```

### Example 4

The following PHP code could be from a shopping cart application. It allows users to apply a discount to an item.

Bad code:

```php
$discount = $_POST['discount'];
$originalPrice = 100.00;
$finalPrice = $originalPrice - ($originalPrice * $discount / 100);
processPayment($finalPrice);
```

Good code:

```php
$original_price = 100.00;
$allowed_discounts = [0, 10, 20, 50]; // only these discounts are valid
$discount = (int) ($_POST['discount'] ?? 0);
if (!in_array($discount, $allowed_discounts, true)) {
    http_response_code(400);
    exit('Invalid discount.');
}
$final_price = $original_price - ($original_price * $discount / 100);
if ($final_price <= 0) {
    http_response_code(400);
    exit('Invalid final price.');
}
processPayment($final_price);
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2025-4037 | ATM simulator does not check for negative values with deposits or withdrawals, allowing attackers to increase their balance |
| 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) |
| 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-2008-1440 | lack of validation of length field leads to infinite loop |
| CVE-2008-2374 | lack of validation of string length fields allows memory consumption or buffer over-read |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2010-3904 | Linux Kernel Improper Input Validation Vulnerability | high | 8.5 | - | Yes | 2010-12-06 |
| CVE-2026-81779 | WordPress Newspapers X theme 1.0.46-1.0.48 - Backdoor vulnerability | critical | 10.0 | - | No | 2026-08-31 |
| CVE-2026-49777 | WordPress Product Slider Pro for WooCommerce plugin \< 3.5.4 - Backdoor vulnerability | critical | 10.0 | - | No | 2026-06-05 |
| CVE-2024-8887 | Authentication bypass vulnerability on CIRCUTOR Q-SMT | critical | 10.0 | - | No | 2024-09-18 |
| CVE-2026-25345 | WordPress SimpLy Gallery plugin \<= 3.3.2 - Arbitrary Code Execution vulnerability | critical | 9.9 | - | No | 2026-03-25 |
| CVE-2026-33972 | In the Exynos modem's IMS stack, Out of Bound access occurs due to improper validation. | critical | 9.8 | - | No | 2026-11-05 |
| CVE-2026-98317 | neighbour: Enforce min/max to NDTPA\_INTERVAL\_PROBE\_TIME\_MS. | critical | 9.8 | - | No | 2026-10-06 |
| CVE-2025-55398 | - | critical | 9.8 | - | No | 2025-08-22 |
| CVE-2025-43964 | LibRaw: Improper Validation of Specified Quantity in Input in LibRaw | critical | 9.8 | - | No | 2025-04-20 |
| CVE-2022-25727 | - | critical | 9.8 | - | No | 2022-11-15 |
| CVE-2022-20385 | - | critical | 9.8 | - | No | 2022-09-13 |
| CVE-2022-37134 | - | critical | 9.8 | - | No | 2022-08-22 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-20](https://radicalnotion.ai/cwe/cwe-20) | Improper Input Validation |
| Child | [CWE-606](https://radicalnotion.ai/cwe/cwe-606) | Unchecked Input for Loop Condition |
| Child | [CWE-839](https://radicalnotion.ai/cwe/cwe-839) | Numeric Range Comparison Without Minimum Check |
| Can precede | [CWE-789](https://radicalnotion.ai/cwe/cwe-789) | Memory Allocation with Excessive Size Value |

## Frequently asked questions

### What is CWE-1284?

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.

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

415 recorded CVEs are attributed to CWE-1284, including CVE-2010-3904, CVE-2026-81779 and CVE-2026-49777. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-1284?

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.

### How is CWE-1284 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-1284?

Exploiting CWE-1284 can lead to: Varies by Context, DoS: Resource Consumption (CPU), Modify Memory, Read Memory.

### Is CWE-1284 actively exploited?

Yes. 1 CWE-1284 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 415 recorded CVEs.

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

---

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