This is an attempt to fix fuzzer issues 1,2,8 reported by practicalswift here : #18046
The fuzzer harness doesn’t prevent deserialization of unrealistic high values for Coin::nHeight. In the provided examples, we have :
blockundo_deserialize: the varint0x8DD88DD700is deserialized as3944983552inCoin::nHeight(TxInOutFormatter::Unser)coins_deserialize: the varint0x8DD5D5EC40is deserialized as3939874496similarlytxundo_deserialize: the varint0x8DCD828F01is deserialized as3921725441inCoin::nHeight(Coin::Unserialize)
Since Coin::nHeight is 31 bit long, multiplying a large value by 2 triggers the fuzzer.
AFAIK those values are unrealistic (~70k years for the smallest..). I’ve looked a bit a reducing the range of values the fuzzer can deserialize, but this seems to be too much code change for not much.
Hence this PR chooses to static cast nHeight when re-serializing; it seems to be the less intrusive/safest way to prevent the fuzzer output.
Another more “upstream” approach would be to limit Coin::nHeight values to something more realistic, e.g. 0xFFFFFFF (~5k years) :
https://github.com/pierreN/bitcoin/blob/de3a30bab28e2db853a795017c5ec1704a1d0fee/src/undo.h#L39 and https://github.com/pierreN/bitcoin/blob/de3a30bab28e2db853a795017c5ec1704a1d0fee/src/coins.h#L71
Thanks !
NB: i was also not sure about the component/area to prefix the PR/commit with.. ?