policy: sum package weight in int64_t #36535

pull fametrano wants to merge 1 commits into bitcoin:master from fametrano:packages-weight-int64 changing 1 files +1 −1
  1. fametrano commented at 7:07 AM on October 15, 2026: contributor

    IsWellFormedPackage sums the package weight with std::accumulate starting from a plain 0, so the running total is an int. A package heavier than INT_MAX would wrap and could pass the MAX_PACKAGE_WEIGHT check. No package that large reaches this check today, since RPC request bodies are capped at 32 MiB and P2P messages at 4 MB, so this is defense in depth. It picks up the one-line fix from #35473, which was closed with an invitation to do so.

    I start the sum from int64_t{0}, as the vsize sum in validation.cpp already does. I did not add a test, since the one on #35473 was turned down. I checked the fix locally with a throwaway test that puts one transaction of 88M weight into a package 25 times: before the fix the package is rejected as package-contains-duplicates, after it as package-too-large.

  2. policy: sum package weight in int64_t
    std::accumulate keeps its running total in the type of its initial
    value. IsWellFormedPackage passed a plain 0, so the package weight was
    summed in an int, even though the lambda and the result are int64_t.
    A package heavier than INT_MAX would wrap and could pass the
    MAX_PACKAGE_WEIGHT check. No such package reaches this check today:
    RPC request bodies and P2P messages are far smaller.
    
    Start the sum from int64_t{0}, as the vsize sum in validation.cpp
    already does.
    faaabe4454
  3. DrahtBot added the label TX fees and policy on Oct 15, 2026
  4. DrahtBot commented at 7:07 AM on October 15, 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 maflcko, instagibbs

    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. maflcko commented at 7:15 AM on October 15, 2026: member

    lgtm ACK faaabe4454c14537e9f23bd349d43d7233df14fe

    as a cosmetic style cleanup. For reference, this is a C++ language bug/pitfall which was fixed in C++23 with fold_left:

    https://godbolt.org/z/9q7YvjPv9

  6. fanquake requested review from instagibbs on Oct 15, 2026
  7. instagibbs commented at 1:09 AM on October 16, 2026: member

    ACK faaabe4454c14537e9f23bd349d43d7233df14fe

  8. fanquake merged this on Oct 16, 2026
  9. fanquake closed this on Oct 16, 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-30 09:40 UTC