You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While the XDR definition specifies int32, the actual Stellar network allows for prices with numerators and denominators exceeding the int32 range. This causes parsing failures when attempting to process such transactions.
Hi, I'd like to investigate and fix the integer overflow in the Price struct. I can add checked arithmetic and a test with boundary values. Could you assign me?
Hi, Leo Cagliero (Open Stellar / Starmaker). I'd like to take this.
Price { n: i32, d: i32 } overflows when comparing or cross-multiplying two prices: a.n * b.d and b.n * a.d are computed in i32, and with large numerators/denominators the product exceeds i32::MAX. The fix is to widen to i64 (or i128) for the intermediate products before comparing:
implPrice{pubfncmp_cross(&self,other:&Price) -> Ordering{// a.n/a.d vs b.n/b.d ==> a.n*b.d vs b.n*a.d (widened)let lhs = i64::from(self.n)* i64::from(other.d);let rhs = i64::from(other.n)* i64::from(self.d);
lhs.cmp(&rhs)}}
i64::from(i32) * i64::from(i32) can never overflow i64, so the comparison stays exact. If there's a place that materializes the product into XDR (not just compares), I'll use checked_mul there and surface an error instead of wrapping. I'll add tests with n = i32::MAX, d = 1 against another large price to confirm no overflow and correct ordering. Could you assign me?
Activity
leocagli commentedon Jun 26, 2026
Hi, I'd like to investigate and fix the integer overflow in the Price struct. I can add checked arithmetic and a test with boundary values. Could you assign me?
leocagli commentedon Jun 27, 2026
Hi, Leo Cagliero (Open Stellar / Starmaker). I'd like to take this.
Price { n: i32, d: i32 }overflows when comparing or cross-multiplying two prices:a.n * b.dandb.n * a.dare computed ini32, and with large numerators/denominators the product exceedsi32::MAX. The fix is to widen toi64(ori128) for the intermediate products before comparing:i64::from(i32) * i64::from(i32)can never overflowi64, so the comparison stays exact. If there's a place that materializes the product into XDR (not just compares), I'll usechecked_multhere and surface an error instead of wrapping. I'll add tests withn = i32::MAX, d = 1against another large price to confirm no overflow and correct ordering. Could you assign me?