Fix/spend div by zero #35061

pull flawlesscode254 wants to merge 3 commits into bitcoin:master from flawlesscode254:fix/spend-div-by-zero changing 3 files +6 −2
  1. flawlesscode254 commented at 4:09 AM on April 12, 2026: none

    When addresses_without_amount is empty, the code attempts to divide by zero when calculating per_output_without_amount and when distributing the remainder. This fix adds a check to ensure the vector is not empty before performing the division, throwing a proper RPC error instead of crashing.

  2. util/moneystr: fix potential out-of-bounds access in FormatMoney
    The loop in FormatMoney accesses str[i-2] without first checking
    that i >= 2. If str.size() < 3, this could read out of bounds.
    
    Fix by adding explicit bounds check i >= 2 to the loop condition.
    30f6c59244
  3. validation: fix potential integer underflow in reverse loop
    When block.vtx is empty, block.vtx.size() - 1 causes underflow
    since size() returns size_t (unsigned). Cast to int to prevent this.
    b0ccce1126
  4. wallet/rpc/spend: fix potential division by zero
    Check if addresses_without_amount is empty before performing
    division to prevent division by zero when no addresses are specified.
    5dfdb6d04b
  5. DrahtBot commented at 4:09 AM on April 12, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  6. in src/wallet/rpc/spend.cpp:1542 in 5dfdb6d04b
    1537 | @@ -1538,6 +1538,10 @@ RPCMethod sendall()
    1538 |                  throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds for fees after creating specified outputs.");
    1539 |              }
    1540 |  
    1541 | +
    1542 | +            if (addresses_without_amount.empty()) {
    


    ViniciusCestarii commented at 12:34 PM on April 12, 2026:

    This check is unreachable. addresses_without_amount is already validated to be non-empty at spend.cpp#L1392:

    if (addresses_without_amount.size() == 0) {
        throw JSONRPCError(RPC_INVALID_PARAMETER, "Must provide at least one address without a specified amount");
    }
    
       
  7. maflcko commented at 6:07 AM on April 13, 2026: member

    ai slop

  8. maflcko closed this on Apr 13, 2026


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-21 09:12 UTC

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