CWE-682: Incorrect Calculation

What is CWE-682?

CWE-682 is Incorrect Calculation. The flaw arises when the product performs a calculation that produces an incorrect or unintended result, and that result is later used in a security-critical decision or for resource management. The database currently holds 27 vulnerabilities mapped to CWE-682 and none of them are in the CISA Known Exploited Vulnerabilities catalog.

OWASP Top 10 Rank-
Related CVES (365 days)27
AbstractionPillar
Likelihood of exploitHigh

Vulnerabilities mapped to CWE-682

27 vulnerabilities800% increase year over year

No data

No vulnerability data in CISA KEV for CWE-682

Official definition

ByMitre CWE

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

Detailed description

CWE-682 occurs when a program computes an incorrect or unintended value and then relies on it in an operation that affects security or resource management. The defect may involve an expression, operator precedence, a size or length calculation, carry handling, bit manipulation, numeric overflow, precision, or conversion between types. When the faulty result is used for authorization, validation, buffer sizing, or resource allocation, a small arithmetic error can propagate into a security logic failure, an out-of-bounds access, resource exhaustion, or unauthorized code execution.

Characteristics

This weakness arises when a calculation does not represent the program's intended result but its output is still used to determine allocation, security checks, or execution state. Causes can include incorrect operator precedence, omitted terms, carry-propagation errors, overflow, unsuitable precision, type conversion, or mishandling values outside a supported range. The weakness is not specific to a language or technology and is recorded as being introduced during implementation.

Common consequences

An incorrect calculation can cause the program to enter an unexpected state and crash or otherwise impair service. In resource allocation, it can contribute to an out-of-bounds operation, potentially causing a crash or unauthorized code execution, and can also result in integer overflow or other resource consumption problems. In privilege or permission assignment, it may grant access to sensitive resources. If it produces an insufficient comparison, it may weaken a protection mechanism or validation routine and allow an attacker to bypass security-critical logic.

ImpactScopeExplanation
DoS: Crash, Exit, or RestartAvailabilityIf the incorrect calculation causes the program to move into an unexpected state, it may lead to a crash or impairment of service.
DoS: Crash, Exit, or Restart, DoS: Resource Consumption (Other), Execute Unauthorized Code or CommandsIntegrity, Confidentiality, AvailabilityIf 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).
Gain Privileges or Assume IdentityAccess ControlIn the context of privilege or permissions assignment, an incorrect calculation can provide an attacker with access to sensitive resources.
Bypass Protection MechanismAccess ControlIf 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.

Risk mitigations

During implementation, understand how the language represents numbers and how that representation affects calculations. Account for byte-size differences, precision, signed and unsigned types, truncation, conversions and casts, NaN behavior, and values outside the representable range. Validate every numeric input against both the required minimum and maximum, choose types appropriate to the operation, and use unsigned types only for values that cannot be negative, such as dimensions or quantities. Select languages, libraries, or frameworks that provide safer numeric handling, including packages such as SafeInt for C++ or IntegerLib for C or C++. Review compiler warnings and eliminate security-relevant issues such as signed and unsigned mismatches in memory operations or use of uninitialized variables.

  1. ImplementationUnderstand 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.
  2. Input Validation · ImplementationPerform 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.
  3. ImplementationUse 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.
  4. Language Selection · Architecture and DesignUse 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++).
  5. Libraries or Frameworks · Architecture and DesignUse 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++).
  6. Compilation or Build Hardening · ImplementationExamine 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

Detection can use manual analysis, automated static analysis, and fuzzing. Manual static analysis is particularly useful for evaluating allocation calculations and finding overflow conditions; it may be more effective than strictly automated techniques for weaknesses tied to design and business rules. Automated static analysis, or SAST, can analyze source or compiled code without execution by modeling data flow and control flow and searching for potentially vulnerable patterns between input sources and sinks. Fuzzing generates many diverse inputs and invokes the code dynamically, which can expose unexpected results such as crashes, memory corruption, or resource consumption and can produce repeatable test cases; it does not guarantee coverage of every calculation or business rule.

MethodApproachEffectiveness
Manual AnalysisThis 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.These may be more effective than strictly automated techniques. This is especially the case with weaknesses that are related to design and business rules.High
Automated Static AnalysisAutomated 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.)-
FuzzingFuzz 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.High

Representative vulnerabilities

The following are representative recorded examples, not an exhaustive list:

  • CVE-2026-7270: an expression omitted parentheses needed for operator precedence, causing an incorrect calculation that led to a buffer overflow.
  • CVE-2020-0022: a mobile phone Bluetooth implementation omitted an offset when calculating packet length, leading to an out-of-bounds write.
  • CVE-2017-8932: a carry-propagation defect in a cryptographic implementation on x86-64 added a carry bit from an unrelated earlier operation.
  • CVE-2010-1378: an incorrect calculation allowed attackers to bypass certificate checks.
  • CVE-2004-1363: a substitution overflow occurred because environment variables were expanded after the length check, leading to a buffer overflow.
Sources (2)

CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.

Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.