---
title: "CWE-1285: Improper Validation of Specified Index, Position, or Offset in Input"
url: https://radicalnotion.ai/cwe/cwe-1285
type: cwe
description: "The product receives input that is expected to specify an index, position, or offset into an indexable resource such as a buffer or file, but it does not validate or incorrectly validates that the specified index/position/offset 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-1285: Improper Validation of Specified Index, Position, or Offset in Input

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

## Description

The product receives input that is expected to specify an index, position, or offset into an indexable resource such as a buffer or file, but it does not validate or incorrectly validates that the specified index/position/offset has the required properties.

Often, indexable resources such as memory buffers or files can be accessed using a specific position, index, or offset, such as an index for an array or a position for a file. When untrusted input is not properly validated before it is used as an index, attackers could access (or attempt to access) unauthorized portions of these resources. This could be used to cause buffer overflows, excessive resource allocation, or trigger unexpected failures.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Other | Varies by Context | - |

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

Effectiveness: High

## Demonstrative examples

### Example 1

The following example retrieves the sizes of messages for a pop3 mail server. The message sizes are retrieved from a socket that returns in a buffer the message number and the message size, the message number (num) and size (size) are extracted from the buffer and the message size is placed into an array using the message number for the array index.

Bad code:

```c
/* capture the sizes of all messages */
int getsizes(int sock, int count, int *sizes) {
    ...
    char buf[BUFFER_SIZE];
    int ok;
    int num, size;

    // read values from socket and added to sizes array
    while ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
    {

        // continue read from socket until buf only contains '.'
        if (DOTLINE(buf))
            break;

        else if (sscanf(buf, "%d %d", &num, &size) == 2)
            sizes[num - 1] = size;
    }
        ...
}
```

Good code:

```c
/* capture the sizes of all messages */
int getsizes(int sock, int count, int *sizes) {
    ...
    char buf[BUFFER_SIZE];
    int ok;
    int num, size;

    // read values from socket and added to sizes array
    while ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
    {

        // continue read from socket until buf only contains '.'
        if (DOTLINE(buf))
            break;

        else if (sscanf(buf, "%d %d", &num, &size) == 2) {
            if (num > 0 && num <= (unsigned)count)
                sizes[num - 1] = size;

            else

                /* warn about possible attempt to induce buffer overflow */
                report(stderr, "Warning: ignoring bogus data for message sizes returned by server.\n");
        }
    }
        ...
}
```

In this example the message number retrieved from the buffer could be a value that is outside the allowable range of indices for the array and could possibly be a negative number. Without proper validation of the value to be used for the array index an array overflow could occur and could potentially lead to unauthorized access to memory addresses and system crashes. The value of the array index should be validated to ensure that it is within the allowable range of indices for the array as in the following code.

### Example 2

In the following example the method displayProductSummary is called from a Web service servlet to retrieve product summary information for display to the user. The servlet obtains the integer value of the product number from the user and passes it to the displayProductSummary method. The displayProductSummary method passes the integer value of the product number to the getProductSummary method which obtains the product summary from the array object containing the project summaries using the integer value of the product number as the array index.

Bad code:

```java
// Method called from servlet to obtain product information
public String displayProductSummary(int index) {
    String productSummary = new String("");

    try {
        String productSummary = getProductSummary(index);

    } catch (Exception ex) {...}

    return productSummary;
}

public String getProductSummary(int index) {
    return products[index];
}
```

Good code:

```java
// Method called from servlet to obtain product information
public String displayProductSummary(int index) {
    String productSummary = new String("");

    try {
        String productSummary = getProductSummary(index);

    } catch (Exception ex) {...}

    return productSummary;
}

public String getProductSummary(int index) {
    String productSummary = "";

    if ((index >= 0) && (index < MAX_PRODUCTS)) {
        productSummary = products[index];
    }
    else {
        System.err.println("index is out of bounds");
        throw new IndexOutOfBoundsException();
    }

    return productSummary;
}
```

Good code:

```java
ArrayList productArray = new ArrayList(MAX_PRODUCTS);
...
try {
    productSummary = (String) productArray.get(index);
} catch (IndexOutOfBoundsException ex) {...}
```

### Example 3

The following example asks a user for an offset into an array to select an item.

Bad code:

```c
int main (int argc, char **argv) {
    char *items[] = {"boat", "car", "truck", "train"};
    int index = GetUntrustedOffset();
    printf("User selected %s\n", items[index-1]);
}
```

The programmer allows the user to specify which element in the list to select, however an attacker can provide an out-of-bounds offset, resulting in a buffer over-read (CWE-126).

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2005-0369 | large ID in packet used as array index |
| CVE-2001-1009 | negative array index as argument to POP LIST command |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-74280 | crypto: marvell/octeontx - fix DMA cleanup using wrong loop index | critical | 10.0 | - | No | 2026-08-15 |
| CVE-2023-54090 | ixgbe: Fix panic during XDP\_TX with \> 64 CPUs | critical | 9.8 | - | No | 2025-12-24 |
| CVE-2022-50717 | nvmet-tcp: add bounds check on Transfer Tag | critical | 9.8 | - | No | 2025-12-24 |
| CVE-2025-39975 | smb: client: fix wrong index reference in smb2\_compound\_op() | critical | 9.8 | - | No | 2025-10-15 |
| CVE-2025-3357 | IBM Tivoli Monitoring code execution | critical | 9.8 | - | No | 2025-05-28 |
| CVE-2026-99679 | xfs: refuse a pNFS LAYOUTCOMMIT of a range without blocks | critical | 9.4 | - | No | 2026-11-20 |
| CVE-2026-80670 | perf tools: Use perf\_env\_\_get\_cpu\_topology() in machine\_\_resolve() | critical | 9.1 | - | No | 2026-08-28 |
| CVE-2026-33557 | Apache Kafka: Missing JWT token validation in OAUTHBEARER authentication | critical | 9.1 | - | No | 2026-04-20 |
| CVE-2025-3755 | Information Disclosure and Denial-of-Service(DoS) Vulnerability in MELSEC iQ-F Series CPU module | critical | 9.1 | - | No | 2025-05-29 |
| CVE-2026-12681 | Go-Attestation: Hash injection into trusted measurement list via unskipped SignatureHeaderSize vendor bytes in parseEfiSignatureList() | high | 8.9 | - | No | 2026-06-24 |
| CVE-2023-54092 | KVM: s390: pv: fix index value of replaced ASCE | high | 8.8 | - | No | 2025-12-24 |
| CVE-2023-53431 | scsi: ses: Handle enclosure with just a primary component gracefully | high | 8.8 | - | No | 2025-09-18 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-20](https://radicalnotion.ai/cwe/cwe-20) | Improper Input Validation |
| Child | [CWE-129](https://radicalnotion.ai/cwe/cwe-129) | Improper Validation of Array Index |
| Child | [CWE-781](https://radicalnotion.ai/cwe/cwe-781) | Improper Address Validation in IOCTL with METHOD\_NEITHER I/O Control Code |

## Frequently asked questions

### What is CWE-1285?

The product receives input that is expected to specify an index, position, or offset into an indexable resource such as a buffer or file, but it does not validate or incorrectly validates that the specified index/position/offset has the required properties.

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

116 recorded CVEs are attributed to CWE-1285, including CVE-2026-74280, CVE-2023-54090 and CVE-2022-50717.

### How do you prevent CWE-1285?

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-1285 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-1285?

Exploiting CWE-1285 can lead to: Varies by Context.

### Is CWE-1285 actively exploited?

116 recorded CVEs are caused by CWE-1285; none are currently in CISA's KEV catalog of actively exploited flaws.

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

---

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