Closes #19278.
Avoid signed integer overflow when loading malformed mempool.dat
files.
Avoid invalid integer negation when loading malformed mempool.dat
files (or when processing prioritisetransaction
RPC calls).
Add note about the valid range of inputs for FormatMoney(...)
.
Add test.
Before this patch:
0$ xxd -p -r > mempool-signed-integer-overflow.dat << "EOF"
101000000000000003f2d3f3f21f800000000000000000000000000000000
26d697464657363656e64616e00000001000000ec000000003d6a6c000000
3000000000000ec9bf601000000000000000000ec9b0001000000000001ff
4fffef900000001000000ec0000000000ec9b000001000000000101000100
500000001000000ec000000003d6a6a000000000000000020ec9b000000fa
600
7EOF
8$ cp mempool-signed-integer-overflow.dat ~/.bitcoin/regtest/mempool.dat
9$ UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1:report_error_type=1" src/bitcoind -regtest
10…
11txmempool.cpp:839:15: runtime error: signed integer overflow: -7211388903327006720 + -7211353718954917888 cannot be represented in type 'long'
12…
0$ xxd -p -r > mempool-invalid-negation.dat << "EOF"
10100000000000000002e000000005d2d000d020000000000000000000000
2200000000000000000000080fc0000002d
3EOF
4$ cp mempool-invalid-negation.dat ~/.bitcoin/regtest/mempool.dat
5$ UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1:report_error_type=1" src/bitcoind -regtest
6…
7util/moneystr.cpp:16:34: runtime error: negation of -9223372036854775808 cannot be represented in type 'CAmount' (aka 'long'); cast to an unsigned type to negate this value to itself
8…
After this patch:
0$ xxd -p -r > mempool-signed-integer-overflow.dat << "EOF"
101000000000000003f2d3f3f21f800000000000000000000000000000000
26d697464657363656e64616e00000001000000ec000000003d6a6c000000
3000000000000ec9bf601000000000000000000ec9b0001000000000001ff
4fffef900000001000000ec0000000000ec9b000001000000000101000100
500000001000000ec000000003d6a6a000000000000000020ec9b000000fa
600
7EOF
8$ cp mempool-signed-integer-overflow.dat ~/.bitcoin/regtest/mempool.dat
9$ UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1:report_error_type=1" src/bitcoind -regtest
10…
112020-11-13T12:34:56Z PrioritiseTransaction(...) failed. Invalid fee delta?
12…
0$ xxd -p -r > mempool-invalid-negation.dat << "EOF"
10100000000000000002e000000005d2d000d020000000000000000000000
2200000000000000000000080fc0000002d
3EOF
4$ cp mempool-invalid-negation.dat ~/.bitcoin/regtest/mempool.dat
5$ UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1:report_error_type=1" src/bitcoind -regtest
6…
72020-11-13T12:34:56Z PrioritiseTransaction(...) failed. Invalid fee delta?
8…