From 3610aa71daeefbb20aeec6c7bea344a00618ed2e Mon Sep 17 00:00:00 2001 From: PiRK Date: Wed, 22 Dec 2021 17:10:13 +0100 Subject: [PATCH] Avoid signed integer overflow when loading a mempool.dat file with a malformed time field Summary: This is a backport of [[https://github.com/bitcoin/bitcoin/pull/20372 | core#20372]] Test Plan: This causes an error before applying the commit, and it works after the change: ``` $ cmake .. -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DENABLE_SANITIZERS=undefined $ xxd -p -r > mempool.dat-crash-1 <GetId(), amountdelta); } TxValidationState state; - if (nTime + nExpiryTimeout > nNow) { + if (nTime > nNow - nExpiryTimeout) { LOCK(cs_main); AcceptToMemoryPoolWithTime(config, pool, state, tx, nTime, false /* bypass_limits */,