fees: prevent divide by zero in CFeeRate #36712

pull ismaelsadeeq wants to merge 1 commits into bitcoin:master from ismaelsadeeq:10-2026-fix-cfeerate-divide-by-zero changing 3 files +12 −1
  1. ismaelsadeeq commented at 4:33 PM on October 30, 2026: member

    A CFeeRate with size 0 GetFeePerK() and CFeeRate+= evaluated EvaluateFeeDown(1000) unconditionally, dividing by that zero size and crashing.

    Return 0 for an empty fee rate, matching GetFee() behaviour, and add minimal unit test coverage.

    This was reported by Jacob F Cudney (aragondragon)

  2. fees: prevent divide by zero in CFeeRate
    A CFeeRate with size 0. GetFeePerK() evaluated EvaluateFeeDown(1000)
    unconditionally, dividing by that zero size and crashing.
    
    Return 0 for an empty fee rate, matching GetFee(), and add coverage.
    40647a2057
  3. DrahtBot added the label TX fees and policy on Oct 30, 2026
  4. DrahtBot commented at 4:33 PM on October 30, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK pablomartin4btc, polespinasa
    Concept ACK darosior

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. ismaelsadeeq commented at 4:33 PM on October 30, 2026: member
  6. in src/test/amount_tests.cpp:96 in 40647a2057
      91 | @@ -92,6 +92,11 @@ BOOST_AUTO_TEST_CASE(GetFeeTest)
      92 |      BOOST_CHECK(CFeeRate(CAmount(27), 789) < CFeeRate(35));
      93 |      // Maximum size in bytes, should not crash
      94 |      CFeeRate(MAX_MONEY, std::numeric_limits<int32_t>::max()).GetFeePerK();
      95 | +    BOOST_CHECK_EQUAL(CFeeRate(0, 0).GetFeePerK(), CAmount{0});
      96 | +    BOOST_CHECK_EQUAL(CFeeRate(CAmount{5}, 0).GetFeePerK(), CAmount{0});
    


    maflcko commented at 4:43 PM on October 30, 2026:

    nit: Could move the tests up to where GetFee() returns zero, so that the same tests are grouped? For the next one, could have a newline, as this test is unrelated from the one about "Maximum size in bytes"?

  7. maflcko approved
  8. maflcko commented at 4:43 PM on October 30, 2026: member

    lgtm

  9. pablomartin4btc commented at 8:14 PM on October 30, 2026: member

    ACK 40647a20572a06b0643e28d92b471a2ab3954de6

  10. darosior commented at 8:48 PM on October 30, 2026: member

    Concept ACK

  11. polespinasa commented at 9:48 PM on October 30, 2026: member

    ACK 40647a20572a06b0643e28d92b471a2ab3954de6

  12. DrahtBot requested review from darosior on Oct 30, 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-10-31 21:51 UTC

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