Course contentsShow
← Security
Lesson 926 of 3,05219. Web Security - Business Logic VulnerabilitiesFree lesson

Integer Overflow in Financial Calculations

Exploiting arithmetic overflow and underflow in price calculations, total amounts, and balance computations.

Integer Overflow in Financial Calculations

You'll learn how attackers exploit arithmetic overflow and underflow to manipulate prices, totals, and balances in web applications.

What Is Integer Overflow?

Integer overflow occurs when a calculation produces a result too large (or too small) for the data type storing it. Instead of expanding to accommodate the value, the number "wraps around" to an unexpected value—like an odometer rolling from 999,999 back to 0.

In financial systems, this can turn massive debts into credits or make expensive purchases appear free.

The Core Vulnerability

Imagine a shopping cart where:

  • Item price: $2,000,000,000
  • Quantity: 2
  • Expected total: $4,000,000,000

If the application uses a 32-bit signed integer (max value: 2,147,483,647), multiplying 2,000,000,000 × 2 = 4,000,000,000 overflows. The stored value wraps around to a negative number or unexpectedly small positive value.

Underflow works similarly: subtracting from zero when using unsigned integers can wrap to the maximum value, turning a $5 refund into billions.

Real-World Exploitation Scenarios

Price × Quantity overflow: Order huge quantities of expensive items to trigger overflow, resulting in negative or minimal totals.

Balance calculations: Add funds repeatedly to overflow account balances beyond security checks.

Discount stacking: Combine multiple percentage discounts until total exceeds 100%, causing negative prices.

Refund manipulation: Request refunds that underflow balance checks, granting undeserved credits.

Why This Matters

Unlike other business logic flaws where you bend the rules, integer overflow breaks the math itself. Applications rarely validate that price × quantity stayed within safe bounds—they trust arithmetic to work correctly.

Key Takeaway: Integer overflow exploits arithmetic limits of data types in financial calculations, turning legitimate operations into security vulnerabilities by causing values to wrap around unexpectedly. Always validate ranges and use appropriate data types for monetary values.