What changed, and why it matters
This is a small defensive fix in Electrum's currency-conversion code. Previously, if an exchange rate was reported as zero, the code treated it the same as a missing rate and returned zero. Other parts of the program could then crash with a 'division by zero' error when converting amounts. The change makes zero rates return a special 'not a number' value instead, so callers can handle it safely. It is a robustness improvement rather than a clear-cut security vulnerability.
No urgent action beyond applying the patch. If maintaining a fork, review other callers of quotes() to ensure they handle Decimal('NaN') gracefully rather than propagating NaN into user-facing totals.
Security signals we found
DivisionByZero crash path removed in exchange-rate conversion
Zero quote now handled identically to missing quote
Fixes public issue #10403
Evidence from the diff
In electrum/exchange_rate.py, ExchangeBase.quotes() changed the guard from if rate is None: to if not rate:. When a quote exists but is zero, the old code returned Decimal(0), which callers could use as a divisor and trigger a DivisionByZero exception. The new code returns Decimal(‘NaN’) for both missing and zero rates, matching the existing NaN handling path. This prevents unhandled exceptions in downstream fiat-conversion logic.
Changed components
electrum/exchange_rate.py: ExchangeBase.quotes()Inspect captured patch +1 / −1
diff --git a/electrum/exchange_rate.py b/electrum/exchange_rate.py
index 96403ca..2f2fc45 100644
--- a/electrum/exchange_rate.py
+++ b/electrum/exchange_rate.py
@@ -209,7 +209,7 @@ class ExchangeBase(Logger):
if ccy == 'BTC':
return Decimal(1)
rate = self._quotes.get(ccy)
- if rate is None:
+ if not rate: # don't return 0 to prevent DivisionByZero exceptions
return Decimal('NaN')
if self._quotes_timestamp + SPOT_RATE_EXPIRY < time.time():
# Our rate is stale. Probably better to return no rate than an incorrect one.
Why this scored 25/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.