---
title: "CWE-1335: Incorrect Bitwise Shift of Integer"
url: https://radicalnotion.ai/cwe/cwe-1335
type: cwe
description: "An integer value is specified to be shifted by a negative amount or an amount greater than or equal to the number of bits contained in the value."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-1335: Incorrect Bitwise Shift of Integer

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

## Description

An integer value is specified to be shifted by a negative amount or an amount greater than or equal to the number of bits contained in the value.

Specifying a value to be shifted by a negative amount is undefined in various languages. Various computer architectures implement this action in different ways. The compilers and interpreters when generating code to accomplish a shift generally do not do a check for this issue.

Specifying an over-shift - a shift greater than or equal to the number of bits contained in a value to be shifted - produces a result that varies by architecture and compiler. In some languages, this action is undefined.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | A developer might use shifts without properly verifying the size and sign of the shift amount. |

## Applicable platforms

**Languages:** C (Undetermined), C++ (Undetermined), C# (Undetermined), Java (Undetermined), JavaScript (Undetermined), Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | DoS: Crash, Exit, or Restart | - |
| Other | Undefined Behavior, Unexpected State, Alter Execution Logic | - |

## Potential mitigations

### Implementation

Implicitly or explicitly add checks and mitigation for negative or over-shift values.

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

A negative shift amount for an x86 or x86\_64 shift instruction will produce the number of bits to be shifted by taking a 2's-complement of the shift amount and effectively masking that amount to the lowest 6 bits for a 64 bit shift instruction.

Bad code:

```c
int choose_bit(int reg_bit, int bit_number_from_elsewhere)
{
    if (NEED_TO_SHIFT)
    {
        reg_bit -= bit_number_from_elsewhere;
    }
    return reg_bit;
}
unsigned int handle_io_register(unsigned int *r)
{
    unsigned int the_bit = 1 << choose_bit(5, 10);
    *r |= the_bit;
    return the_bit;
}
```

Good code:

```c
int choose_bit(int reg_bit, int bit_number_from_elsewhere)
{
    if (NEED_TO_SHIFT)
    {
        reg_bit -= bit_number_from_elsewhere;
    }
    return reg_bit;
}

unsigned int handle_io_register(unsigned int *r)
{
    int the_bit_number = choose_bit(5, 10);
    if ((the_bit_number > 0) && (the_bit_number < 63))
    {
        unsigned int the_bit = 1 << the_bit_number;
        *r |= the_bit;
    }
    return the_bit;
}
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2023-4720 | multimedia product performs a left shift with a negative value, leading to a crash |
| CVE-2009-4307 | An unexpected large value in the ext4 filesystem causes an overshift condition resulting in a divide by zero. |
| CVE-2012-2100 | An unexpected large value in the ext4 filesystem causes an overshift condition resulting in a divide by zero - fix of CVE-2009-4307. |
| CVE-2020-8835 | An overshift in a kernel allowed out of bounds reads and writes resulting in a root takeover. |
| CVE-2015-1607 | Program is not properly handling signed bitwise left-shifts causing an overlapping memcpy memory range error. |
| CVE-2016-9842 | Compression function improperly executes a signed left shift of a negative integer. |
| CVE-2018-18445 | Some kernels improperly handle right shifts of 32 bit numbers in a 64 bit register. |
| CVE-2013-4206 | Putty has an incorrectly sized shift value resulting in an overshift. |
| CVE-2018-20788 | LED driver overshifts under certain conditions resulting in a DoS. |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2025-71305 | drm/display/dp\_mst: Add protection against 0 vcpi | critical | 9.8 | - | No | 2026-05-27 |
| CVE-2016-9842 | zlib: Undefined left shift of negative number | high | 8.8 | - | No | 2017-05-23 |
| CVE-2023-52810 | fs/jfs: Add check for negative db\_l2nbperpage | high | 8.4 | - | No | 2024-05-21 |
| CVE-2024-50139 | KVM: arm64: Fix shift-out-of-bounds bug | high | 7.9 | - | No | 2024-11-07 |
| CVE-2026-72483 | usb: host: max3421: Fix shift-out-of-bounds in max3421\_hub\_control() | high | 7.8 | - | No | 2026-08-15 |
| CVE-2026-72450 | xfrm: validate selector family and prefixlen during match | high | 7.8 | - | No | 2026-08-15 |
| CVE-2026-72350 | netfilter: xt\_u32: reject invalid shift counts | high | 7.8 | - | No | 2026-08-15 |
| CVE-2025-38230 | jfs: validate AG parameters in dbMount() to prevent crashes | high | 7.8 | - | No | 2025-07-04 |
| CVE-2026-88357 | - | high | 7.5 | - | No | 2026-09-24 |
| CVE-2026-89971 | nvme: skip the zoned limits update if the zone info query failed | high | 7.5 | - | No | 2026-09-16 |
| CVE-2026-72347 | netfilter: xt\_connmark: reject invalid shift parameters | high | 7.3 | - | No | 2026-08-15 |
| CVE-2026-99182 | ASoC: SOF: ipc4-topology: Fix shift-out-of-bounds for aggregated ALH capture | high | 7.1 | - | No | 2026-10-28 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-682](https://radicalnotion.ai/cwe/cwe-682) | Incorrect Calculation |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| OpenSSF Secure Coding Guide for Python | Use Arithmetic Over Bitwise Operations | pyscg-0003 | - |

## Frequently asked questions

### What is CWE-1335?

An integer value is specified to be shifted by a negative amount or an amount greater than or equal to the number of bits contained in the value.

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

34 recorded CVEs are attributed to CWE-1335, including CVE-2025-71305, CVE-2016-9842 and CVE-2023-52810.

### How do you prevent CWE-1335?

Implicitly or explicitly add checks and mitigation for negative or over-shift values.

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

Exploiting CWE-1335 can lead to: DoS: Crash, Exit, or Restart, Undefined Behavior, Unexpected State, Alter Execution Logic.

### Is CWE-1335 actively exploited?

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

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

---

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