policy: sum package weight in int64_t #36535

Manually merged
fametrano merged 1 commit from packages-weight-int64 into master 2026-10-16 01:27:47 +00:00 AGit
fametrano commented 2026-10-15 07:07:46 +00:00 (Migrated from github.com)

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.

`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`.
DrahtBot commented 2026-10-15 07:07:54 +00:00 (Migrated from github.com)

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36535 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36535.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36535#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/36535#issuecomment-6186677574), [instagibbs](https://github.com/bitcoin/bitcoin/pull/36535#issuecomment-6205710206) | 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-->
First-time contributor

Base: 649bc0a645eb127a9b1e6d078f8d129be6380c87
Head: faaabe4454c14537e9f23bd349d43d7233df14fe

I found no actionable issues in this static review.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `649bc0a645eb127a9b1e6d078f8d129be6380c87` Head: `faaabe4454c14537e9f23bd349d43d7233df14fe` I found no actionable issues in this static review. [Full review report](<https://review.fish.foo/traces/36535-faaabe4454c14537e9f23bd349d43d7233df14fe-793-1.html>)
maflcko commented 2026-10-15 07:15:56 +00:00 (Migrated from github.com)

lgtm ACK faaabe4454

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

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
instagibbs commented 2026-10-16 01:09:26 +00:00 (Migrated from github.com)
ACK faaabe4454c14537e9f23bd349d43d7233df14fe
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36535
No description provided.