CWE-1339: Insufficient Precision or Accuracy of a Real Number
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.
How it's found
Insufficient Precision or Accuracy of a Real Number is typically found by tracing untrusted input from where it enters the system to the point where it is used without the check or neutralization this weakness describes, combining manual code review with dynamic testing.
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. There are multiple ways to store the fractional part of a real number in a computer. In all of these cases, there is a limit to the accuracy of recording a fraction. 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.
Vulnerable vs. safe
108.0 - ((815.0 - 1500.0 / z) / y);
x.push(rec_float(x[number - 1], x[number - 2]));let mut x: Vec<f64> = vec![4.0, 4.25];(2..turns + 1).for_each(|number|{});x[turns]fn rec_float(y: f64, z: f64) -> f64{}fn float_calc(turns: usize) -> f64{}- ((BigRational::from_integer(BigInt::from(815))- BigRational::from_integer(BigInt::from(1500)) / z)/ y)BigRational::from_integer(BigInt::from(108))
x.push(rec_big(x[number - 1].clone(), x[number - 2].clone()));let mut x: Vec<BigRational> = vec![BigRational::from_float(4.0).unwrap(), BigRational::from_float(4.25).unwrap(),];(2..turns + 1).for_each(|number|{});x[turns].clone()Use num_rational::BigRational;fn rec_big(y: BigRational, z: BigRational) -> BigRational{}fn big_calc(turns: usize) -> BigRational{}Consequences
- 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.
- 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.
- 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.
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.
Where this fits in a TurboPentest engagement
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Frequently asked questions
What is CWE-1339?
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.
How do you find Insufficient Precision or Accuracy of a Real Number?
Insufficient Precision or Accuracy of a Real Number is typically found by tracing untrusted input from where it enters the system to the point where it is used without the check or neutralization this weakness describes, combining manual code review with dynamic testing.
What is the impact of CWE-1339?
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. 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. 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.
Does TurboPentest test for Insufficient Precision or Accuracy of a Real Number?
This weakness is not covered by the automated black-box pentest. IntegSec pentesters cover it in a manual engagement.
Related CWEs
Written and reviewed by
Michel Chamberland - Founder & CEO, IntegSec
CISSP, OSCP, OSCE, CEH, GIAC, CCSK · 20+ years in offensive security
Michel has spent 20+ years on offensive security teams including IBM X-Force Red and Trustwave SpiderLabs, leading penetration tests, red team engagements, and breach response for Fortune 500 customers. He is the founder of IntegSec and the architect of TurboPentest.
Find these issues before an attacker does
TurboPentest runs an agentic AI pentest against your target and reports findings with proof, from $99 per target.
Start a pentest