diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 823d2303c81fdb..1b37605373dd81 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -3259,6 +3259,12 @@ static RPCHelpMan loadtxoutset() ChainstateManager& chainman = EnsureChainman(node); const fs::path path{AbsPathForConfigVal(EnsureArgsman(node), fs::u8path(self.Arg("path")))}; + if (!fs::exists(path)) { + throw JSONRPCError( + RPC_INVALID_PARAMETER, + "Txoutset snapshot file " + path.utf8string() + " does not exist."); + } + FILE* file{fsbridge::fopen(path, "rb")}; AutoFile afile{file}; if (afile.IsNull()) { diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index 8addb7e2385f79..097b97e15cbd38 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -10,6 +10,7 @@ `CRegTestParams::m_assumeutxo_data` in `src/kernel/chainparams.cpp`. """ from shutil import rmtree +import platform from dataclasses import dataclass from test_framework.blocktools import ( @@ -190,6 +191,12 @@ def test_invalid_file_path(self): self.log.info("Test bitcoind should fail when file path is invalid.") node = self.nodes[0] path = node.datadir_path / node.chain / "invalid" / "path" + assert_raises_rpc_error(-8, "Txoutset snapshot file {} does not exist.".format(path), node.loadtxoutset, path) + + def test_invalid_file_permissions(self): + self.log.info("Test bitcoind should fail when file has no read permissions.") + node = self.nodes[0] + path = "/dev/loop-control" assert_raises_rpc_error(-8, "Couldn't open file {} for reading.".format(path), node.loadtxoutset, path) def test_snapshot_with_less_work(self, dump_output_path): @@ -455,6 +462,8 @@ def check_dump_output(output): self.test_invalid_snapshot_scenarios(dump_output['path']) self.test_invalid_chainstate_scenarios() self.test_invalid_file_path() + if platform.system() != "Windows": + self.test_invalid_file_permissions() self.test_snapshot_block_invalidated(dump_output['path']) self.test_snapshot_not_on_most_work_chain(dump_output['path'])