Repository navigation
Conversation
CFeeRate constructors turn a non-positive size into the empty feerate
{0, 0}, but Unserialize read fee and size from the stream unchecked.
A negative size then reaches FeeFrac::EvaluateFee, which requires a
positive size: debug builds hit an Assume failure, and release builds
compute wrong fees. A zero size with a nonzero fee compares as an
infinite feerate.
Nothing deserializes a CFeeRate on master, but the UnstableChain IPC
interface in bitcoin#29409, used by the multiprocess wallet in bitcoin#10102, passes
feerates as serialized Data fields, so an IPC client could send these
values.
Throw on values the constructors cannot produce, like other
deserialization errors.
This issue was found by Project Loupe and passed on by Greg Sanders.
This change was written with Claude Opus 5.5.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. |
|
Can the IPC client not still cause aborts via ftrapv or incorrect results, by just passing a feerate so large that it overflows later calculations? |
|
re: #36816 (comment)
This might be possible, and if it is, it seems like the type of fix that would belong in #36520, which adds extra error checking to IPC methods, since it's not specific to the CFeeRate class and could happen with other numeric arguments. Or if you're suggesting the problem here does not necessarily need to be solved, and it's ok for debug builds to crash and release builds to produce bad results if they are given bad values, maybe that could make sense too. This PR is narrower: it only rejects serialized values that CFeeRate's constructors can't produce, like a negative size, which hits |
|
Ok, I see. Maybe turn this into a draft for now, given that it modifies dead/unreachable code and depends on #29409, which is not a draft, but again depends on bitcoin-core/libmultiprocess#377? Once the code is reachable, a small dummy test of the form #36093 could be added to this pull? |

Problem: With the
UnstableChainIPC interface from #29409 merged, an IPC client could makebitcoin-nodehit anAssumefailure (debug builds) or compute wrong fees (release builds) by passing a malformed feerate tobroadcastTransaction,calculateIndividualBumpFeesorcalculateCombinedBumpFee. These methods take feerates as serializedDatafields, andCFeeRatedeserialization reads the fee and size without the checks its constructors do, so it accepts a negative size, which fee calculations require to be positive, and a zero size with a nonzero fee, which compares as an infinite feerate. Nothing deserializes aCFeeRateon master today.Solution: Make
CFeeRatedeserialization throw on values its constructors cannot produce, the same way other malformed serialized data is rejected. The change is aSER_READcheck insrc/policy/feerate.hplus a unit test. It is similar to #36520, which handles other invalid arguments toChainIPC methods.This issue was found by Project Loupe and passed on by instagibbs.