Unchecked bounds on btc amounts in BIP70 implementation #5622

issue SergioDemianLerner opened this issue on January 8, 2015
  1. SergioDemianLerner commented at 5:12 PM on January 8, 2015: contributor

    Bitcoin amounts are stored as uint64 in the protobuf messages. Amounts over 0x7FFFFFFFFFFFFFFF will be considered negative when this line is executed: QList<std::pair<CScript, CAmount> > sendingTos = request.getPayTo(); (in PaymentServer::processPaymentRequest() in qt\paymentserver.cpp)

    Negative values should be discarded by the dust check : if (txOut.IsDust(::minRelayTxFee)) Nevertheless recipient.amount will still accumulate all positive values and may overflow, since the payment protocol allows the merchant to specify many output addresses and each one has a separate amount. So it is still possible to create a small positive total amount by overflowing the int64 range with several large positive amounts. For example: max_uint64 /3 + max_uint64 /3 + max_uint64 /3 +2 == 1 The user will be presented with a dialog asking to pay a total of 1 BTC, but internally the operation will fail, because the independent constituent payment amounts will not be able to be fulfilled.

    This has the nasty effect that the user may think he may have been robbed, because even if the user has 100 BTC, the software will tell the user "The amount exceeds your balance." when paying to an overflowed 1 BTC.

    There may be other possibilities, since there are several places where conversions between uint64 and int64 take place.

    Suggested correction:

    bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient) { .... CTxOut txOut(sendingTo.second, sendingTo.first); // BEGIN ADD if (!MoneyRange(sendingTo.second)) { emit message(tr("Payment request rejected"), tr("Invalid money range."), CClientUIInterface::MSG_ERROR); return false; } // END ADD .... recipient.amount += sendingTo.second; ... // BEGIN ADD if (!MoneyRange(recipient.amount)) { emit message(tr("Payment request rejected"), tr("Invalid accumulated money range."), CClientUIInterface::MSG_ERROR); return false; } // END ADD

  2. lucayepa referenced this in commit adee0a0042 on Mar 9, 2015
  3. laanwj commented at 10:53 AM on October 27, 2015: member

    Fixed by #5629, thanks for reporting

  4. MarcoFalke commented at 11:15 AM on October 27, 2015: member

    Can be closed because it's already fixed.

  5. laanwj closed this on Oct 27, 2015

  6. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me