---
title: "CWE-682: Incorrect Calculation"
url: https://radicalnotion.ai/cwe/cwe-682
type: cwe
description: "The product performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-682: Incorrect Calculation

- **Abstraction:** Pillar
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 170
- **Of those, in CISA KEV:** 0
- **New in 2026:** 53
- **CWE catalog version:** 4.21

## Description

The product performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management.

## Modes of introduction

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

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability | DoS: Crash, Exit, or Restart | If the incorrect calculation causes the program to move into an unexpected state, it may lead to a crash or impairment of service. |
| Integrity, Confidentiality, Availability | DoS: Crash, Exit, or Restart, DoS: Resource Consumption (Other), Execute Unauthorized Code or Commands | If the incorrect calculation is used in the context of resource allocation, it could lead to an out-of-bounds operation (CWE-119) leading to a crash or even arbitrary code execution. Alternatively, it may result in an integer overflow (CWE-190) and / or a resource consumption problem (CWE-400). |
| Access Control | Gain Privileges or Assume Identity | In the context of privilege or permissions assignment, an incorrect calculation can provide an attacker with access to sensitive resources. |
| Access Control | Bypass Protection Mechanism | If the incorrect calculation leads to an insufficient comparison (CWE-697), it may compromise a protection mechanism such as a validation routine and allow an attacker to bypass the security-critical code. |

## Potential mitigations

### Implementation

Understand your programming language's underlying representation and how it interacts with numeric calculation. Pay close attention to byte size discrepancies, precision, signed/unsigned distinctions, truncation, conversion and casting between types, "not-a-number" calculations, and how your language handles numbers that are too large or too small for its underlying representation.

### Implementation (Input Validation)

Perform input validation on any numeric input by ensuring that it is within the expected range. Enforce that the input meets both the minimum and maximum requirements for the expected range.

### Implementation

Use the appropriate type for the desired action. For example, in C/C++, only use unsigned types for values that could never be negative, such as height, width, or other numbers related to quantity.

### Architecture and Design (Language Selection)

Use languages, libraries, or frameworks that make it easier to handle numbers without unexpected consequences.

Examples include safe integer handling packages such as SafeInt (C++) or IntegerLib (C or C++).

### Architecture and Design (Libraries or Frameworks)

Use languages, libraries, or frameworks that make it easier to handle numbers without unexpected consequences.

Examples include safe integer handling packages such as SafeInt (C++) or IntegerLib (C or C++).

### Implementation (Compilation or Build Hardening)

Examine compiler warnings closely and eliminate problems with potential security implications, such as signed / unsigned mismatch in memory operations, or use of uninitialized variables. Even if the weakness is rarely exploitable, a single failure may lead to the compromise of the entire system.

## Detection methods

### Manual Analysis

This weakness can be detected using tools and techniques that require manual (human) analysis, such as penetration testing, threat modeling, and interactive tools that allow the tester to record and modify an active session.

Specifically, manual static analysis is useful for evaluating the correctness of allocation calculations. This can be useful for detecting overflow conditions (CWE-190) or similar weaknesses that might have serious security impacts on the program.

Effectiveness: High. These may be more effective than strictly automated techniques. This is especially the case with weaknesses that are related to design and business rules.

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

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

Effectiveness: High

## Demonstrative examples

### Example 1

The following image processing code allocates a table for images.

Bad code:

```c
img_t table_ptr; /*struct containing img data, 10kB each*/
int num_imgs;
...
num_imgs = get_num_imgs();
table_ptr = (img_t*)malloc(sizeof(img_t)*num_imgs);
...
```

This code intends to allocate a table of size num\_imgs, however as num\_imgs grows large, the calculation determining the size of the list will eventually overflow (CWE-190). This will result in a very small list to be allocated instead. If the subsequent code operates on the list as if it were num\_imgs long, it may result in many types of out-of-bounds problems (CWE-119).

### Example 2

This code attempts to calculate a football team's average number of yards gained per touchdown.

Bad code:

```java
...
int touchdowns = team.getTouchdowns();
int yardsGained = team.getTotalYardage();
System.out.println(team.getName() + " averages " + yardsGained / touchdowns + "yards gained for every touchdown scored");
...
```

The code does not consider the event that the team they are querying has not scored a touchdown, but has gained yardage. In that case, we should expect an ArithmeticException to be thrown by the JVM. This could lead to a loss of availability if our error handling code is not set up correctly.

### Example 3

This example attempts to calculate the position of the second byte of a pointer.

Bad code:

```c
int *p = x;
char * second_char = (char *)(p + 1);
```

In this example, second\_char is intended to point to the second byte of p. But, adding 1 to p actually adds sizeof(int) to p, giving a result that is incorrect (3 bytes off on 32-bit platforms). If the resulting memory address is read, this could potentially be an information leak. If it is a write, it could be a security-critical write to unauthorized memory-- whether or not it is a buffer overflow. Note that the above code may also be wrong in other ways, particularly in a little endian environment.

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2026-7270 | Chain: calculation expression does not use parentheses to address operator precedence (CWE-783), causing an incorrect calculation (CWE-682) leading to a buffer overflow (CWE-787). |
| CVE-2020-0022 | Chain: mobile phone Bluetooth implementation does not include offset when calculating packet length (CWE-682), leading to out-of-bounds write (CWE-787) |
| CVE-2017-8932 | "carry propagation" bug in cryptography implementation on x86-64 architecture adds a carry bit from a previous unrelated operation. |
| CVE-2010-1378 | Chain: incorrect calculation (CWE-682) allows attackers to bypass certificate checks (CWE-295) |
| CVE-2004-1363 | substitution overflow: buffer overflow using environment variables that are expanded after the length check is performed |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2023-2163 | Incorrect Verifier Branch Pruning Logic Leads To Arbitrary Read/Write In Linux Kernel and Lateral Privilege Escalation | critical | 10.0 | - | No | 2023-09-20 |
| CVE-2026-89558 | md/raid10: fix still\_degraded being inverted in raid10\_sync\_request() | critical | 9.8 | - | No | 2026-09-11 |
| CVE-2026-45988 | rxrpc: Fix re-decryption of RESPONSE packets | critical | 9.8 | - | No | 2026-05-27 |
| CVE-2024-36736 | - | critical | 9.8 | - | No | 2024-06-06 |
| CVE-2022-30600 | Incorrect Calculation in moodle | critical | 9.8 | - | No | 2022-05-18 |
| CVE-2021-44847 | toxcore: stack-based buffer overflow in handle\_request() in DHT.c | critical | 9.8 | - | No | 2021-12-13 |
| CVE-2021-38194 | Calculation error in ark-r1cs-std | critical | 9.8 | - | No | 2021-08-08 |
| CVE-2020-0221 | - | critical | 9.8 | - | No | 2020-05-14 |
| CVE-2018-8319 | MSR JavaScript Cryptography Library Security Feature Bypass Vulnerability | critical | 9.8 | - | No | 2018-07-11 |
| CVE-2026-113007 | Incorrect calculation in Permissions | critical | 9.6 | - | No | 2026-10-20 |
| CVE-2026-89914 | KVM: arm64: Sign-extend VA for range-based TLBI invalidation | critical | 9.3 | - | No | 2026-09-16 |
| CVE-2026-53670 | PREVAIL: Non-singleton typeset in add() skips offset update, allowing OOB access to pass eBPF verification | critical | 9.3 | - | No | 2026-09-02 |

## Related attack patterns (CAPEC)

- [CAPEC-128](https://radicalnotion.ai/capec/capec-128): Integer Attacks
- [CAPEC-129](https://radicalnotion.ai/capec/capec-129): Pointer Manipulation

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Child | [CWE-128](https://radicalnotion.ai/cwe/cwe-128) | Wrap-around Error |
| Child | [CWE-131](https://radicalnotion.ai/cwe/cwe-131) | Incorrect Calculation of Buffer Size |
| Child | [CWE-135](https://radicalnotion.ai/cwe/cwe-135) | Incorrect Calculation of Multi-Byte String Length |
| Child | [CWE-190](https://radicalnotion.ai/cwe/cwe-190) | Integer Overflow or Wraparound |
| Child | [CWE-191](https://radicalnotion.ai/cwe/cwe-191) | Integer Underflow (Wrap or Wraparound) |
| Child | [CWE-193](https://radicalnotion.ai/cwe/cwe-193) | Off-by-one Error |
| Child | [CWE-369](https://radicalnotion.ai/cwe/cwe-369) | Divide By Zero |
| Child | [CWE-468](https://radicalnotion.ai/cwe/cwe-468) | Incorrect Pointer Scaling |
| Child | [CWE-469](https://radicalnotion.ai/cwe/cwe-469) | Use of Pointer Subtraction to Determine Size |
| Child | [CWE-1335](https://radicalnotion.ai/cwe/cwe-1335) | Incorrect Bitwise Shift of Integer |
| Child | [CWE-1339](https://radicalnotion.ai/cwe/cwe-1339) | Insufficient Precision or Accuracy of a Real Number |
| Can precede | [CWE-170](https://radicalnotion.ai/cwe/cwe-170) | Improper Null Termination |
| Related | [CWE-681](https://radicalnotion.ai/cwe/cwe-681) | Incorrect Conversion between Numeric Types |
| Related | [CWE-839](https://radicalnotion.ai/cwe/cwe-839) | Numeric Range Comparison Without Minimum Check |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CERT C Secure Coding | Prevent or detect domain and range errors in math functions | FLP32-C | CWE More Abstract |
| CERT C Secure Coding | Use only explicitly signed or unsigned char type for numeric values | INT07-C | - |
| CERT C Secure Coding | Use bitwise operators only on unsigned operands | INT13-C | - |
| CERT C Secure Coding | Ensure that division and remainder operations do not result in divide-by-zero errors | INT33-C | CWE More Abstract |
| CERT C Secure Coding | Do not shift an expression by a negative number of bits or by greater than or equal to the number of bits that exist in the operand | INT34-C | CWE More Abstract |

## Frequently asked questions

### What is CWE-682?

The product performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management.

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

170 recorded CVEs are attributed to CWE-682, including CVE-2023-2163, CVE-2026-89558 and CVE-2026-45988.

### How do you prevent CWE-682?

Understand your programming language's underlying representation and how it interacts with numeric calculation. Pay close attention to byte size discrepancies, precision, signed/unsigned distinctions, truncation, conversion and casting between types, "not-a-number" calculations, and how your language handles numbers that are too large or too small for its underlying representation.

### How is CWE-682 detected?

Manual Analysis: This weakness can be detected using tools and techniques that require manual (human) analysis, such as penetration testing, threat modeling, and interactive tools that allow the tester to record and modify an active session.

### What are the consequences of CWE-682?

Exploiting CWE-682 can lead to: DoS: Crash, Exit, or Restart, DoS: Resource Consumption (Other), Execute Unauthorized Code or Commands, Gain Privileges or Assume Identity, Bypass Protection Mechanism.

### Is CWE-682 actively exploited?

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

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

---

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