CWEweakness

CWE-1339 Insufficient Precision or Accuracy of a Real Number

Official page ↗
Abstraction
Base
Structure
Simple
Status
Draft
Languages
Not Language-Specific, Python
CWE version
5.0

Description

The product processes a real number with an implementation in which the number's representation does not preserve required accuracy and precision in its fractional part, causing an incorrect result.

Extended description

When a security decision or calculation requires highly precise, accurate numbers such as financial calculations or prices, then small variations in the number could be exploited by an attacker. If the fraction can be represented in a fixed number of digits (binary or decimal), there might not be enough digits assigned to represent the number. In other cases, the number cannot be represented in a fixed number of digits due to repeating in decimal or binary notation (e.g. 0.333333...) or due to a transcendental number such as Π or √2. Rounding of numbers can lead to situations where the computer results do not adequately match the result of sufficiently accurate math.

Common consequences

• Availability: DoS: Crash, Exit, or Restart — This weakness will generally lead to undefined results and therefore crashes. In some implementations the program will halt if the weakness causes an overflow during a calculation. • Integrity: Execute Unauthorized Code or Commands — The results of the math are not as expected. This could cause issues where a value would not be properly calculated and provide an incorrect answer. • Confidentiality, Availability, Access Control: Read Application Data, Modify Application Data — This weakness can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a product's implicit security policy.

Potential mitigations

• [Implementation, Patching and Maintenance] The developer or maintainer can move to a more accurate representation of real numbers. In extreme cases, the programmer can move to representations such as ratios of BigInts which can represent real numbers to extremely fine precision. The programmer can also use the concept of an Unum real. The memory and CPU tradeoffs of this change must be examined. Since floating point reals are used in many products and many locations, they are implemented in hardware and most format changes will cause the calculations to be moved into software resulting in slower products.

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

Observed examples

• CVE-2018-16069: Chain: series of floating-point precision errors (CWE-1339) in a web browser rendering engine causes out-of-bounds read (CWE-125), giving access to cross-origin data • CVE-2017-7619: Chain: rounding error in floating-point calculations (CWE-1339) in image processor leads to infinite loop (CWE-835) • CVE-2021-29529: Chain: machine-learning product can have a heap-based buffer overflow (CWE-122) when some integer-oriented bounds are calculated by using ceiling() and floor() on floating point values (CWE-1339) • CVE-2008-2108: Chain: insufficient precision (CWE-1339) in random-number generator causes some zero bits to be reliably generated, reducing the amount of entropy (CWE-331). • CVE-2006-6499: Chain: web browser crashes due to infinite loop - "bad looping logic [that relies on] floating point math [CWE-1339] to exit the loop [CWE-835]"

Related

Observed example · CVE (5)

  • CVE-2021-29529 TensorFlow is an end-to-end open source platform for machine learning. vulnerability
  • CVE-2018-16069 Unintended floating-point error accumulation in SwiftShader in Google Chrome prior to 69.0.3497.81 allowed a remote attacker to leak… vulnerability
  • CVE-2017-7619 In ImageMagick 7.0.4-9, an infinite loop can occur because of a floating-point rounding error in some of the color algorithms. vulnerability
  • CVE-2008-2108 The GENERATE_SEED macro in PHP 4.x before 4.4.8 and 5.x before 5.2.5, when running on 64-bit systems, performs a multiplication that… vulnerability
  • CVE-2006-6499 The js_dtoa function in Mozilla Firefox 2.x before 2.0.0.1, 1.5.x before 1.5.0.9, Thunderbird before 1.5.0.9, and SeaMonkey before 1.0.7… vulnerability

Can precede · CWE (2)

  • CWE-119 Improper Restriction of Operations within the Bounds of a Memory Buffer weakness
  • CWE-834 Excessive Iteration weakness

Child of · CWE (1)

  • CWE-682 Incorrect Calculation weakness

Peer of · CWE (1)

  • CWE-190 Integer Overflow or Wraparound weakness

Referenced by CVE · weakness (1)

  • CVE-2026-88360 libvips 8.19.0 contains a memory access vulnerability when processing little-endian PFM images. vulnerability