diff --git a/src/wallet/rpchushwallet.cpp b/src/wallet/rpchushwallet.cpp index f40764e7e..61b951da7 100644 --- a/src/wallet/rpchushwallet.cpp +++ b/src/wallet/rpchushwallet.cpp @@ -550,7 +550,7 @@ void zsWalletTxJSON(const CWalletTx& wtx, UniValue& ret, const std::string strAd tx.push_back(Pair("expiryheight", (int64_t)wtx.nExpiryHeight)); tx.push_back(Pair("confirmations", confirms)); tx.push_back(Pair("time", wtx.GetTxTime())); - tx.push_back(Pair("size", static_cast(GetSerializeSize(static_cast(wtx), SER_NETWORK, PROTOCOL_VERSION)))); + tx.push_back(Pair("size", static_cast(GetSerializeSize(static_cast(wtx), SER_NETWORK, PROTOCOL_VERSION)))); //Wallet Conflicts UniValue conflicts(UniValue::VARR); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d09f0fad4..eb5970894 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1805,7 +1805,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe entry.push_back(Pair("fee", ValueFromAmount(-nFee))); if (fLong) WalletTxToJSON(wtx, entry); - entry.push_back(Pair("size", static_cast(GetSerializeSize(static_cast(wtx), SER_NETWORK, PROTOCOL_VERSION)))); + entry.push_back(Pair("size", static_cast(GetSerializeSize(static_cast(wtx), SER_NETWORK, PROTOCOL_VERSION)))); ret.push_back(entry); } } @@ -1850,7 +1850,7 @@ void ListTransactions(const CWalletTx& wtx, const string& strAccount, int nMinDe entry.push_back(Pair("vout", r.vout)); if (fLong) WalletTxToJSON(wtx, entry); - entry.push_back(Pair("size", static_cast(GetSerializeSize(static_cast(wtx), SER_NETWORK, PROTOCOL_VERSION)))); + entry.push_back(Pair("size", static_cast(GetSerializeSize(static_cast(wtx), SER_NETWORK, PROTOCOL_VERSION)))); ret.push_back(entry); } } @@ -1952,6 +1952,10 @@ UniValue listtransactions(const UniValue& params, bool fHelp, const CPubKey& myp throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative count"); if (nFrom < 0) throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative from"); + // nCount + nFrom wraps negative otherwise (-fwrapv), and the window below then indexes far out of + // bounds. No wallet has INT_MAX entries, so clamping changes no valid reply. + if (nCount > std::numeric_limits::max() - nFrom) + nCount = std::numeric_limits::max() - nFrom; UniValue ret(UniValue::VARR); @@ -2240,7 +2244,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp, const CPubKey& mypk) ListTransactions(wtx, "*", 0, false, details, filter); entry.push_back(Pair("details", details)); - string strHex = EncodeHexTx(static_cast(wtx)); + string strHex = EncodeHexTx(static_cast(wtx)); entry.push_back(Pair("hex", strHex)); return entry; @@ -5185,8 +5189,17 @@ UniValue z_viewtransaction(const UniValue& params, bool fHelp, const CPubKey& my continue; } auto op = res->second; - auto wtxPrev = pwalletMain->mapWallet.at(op.hash); - auto decrypted = wtxPrev.DecryptSaplingNote(op).get(); + // By reference: a CWalletTx copy deep-copies every note's witness list. The nullifier map can + // outlive the tx it points to (DeleteTransactions doesn't prune it); skip such a spend like an + // unknown one instead of failing the whole call with "map::at". + std::map::const_iterator itPrev = pwalletMain->mapWallet.find(op.hash); + if (itPrev == pwalletMain->mapWallet.end()) + continue; + const CWalletTx& wtxPrev = itPrev->second; + auto maybeDecrypted = wtxPrev.DecryptSaplingNote(op); + if (!maybeDecrypted) + continue; + auto decrypted = maybeDecrypted.get(); auto notePt = decrypted.first; auto pa = decrypted.second; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 67049a74f..26c916429 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3351,12 +3351,14 @@ boost::optional> CWalletTx::DecryptSaplingNote(SaplingOutPoint op) const { // Check whether we can decrypt this SaplingOutPoint - if (this->mapSaplingNoteData.count(op) == 0) { + mapSaplingNoteData_t::const_iterator ndIt = this->mapSaplingNoteData.find(op); + if (ndIt == this->mapSaplingNoteData.end()) { return boost::none; } - auto output = this->vShieldedOutput[op.n]; - auto nd = this->mapSaplingNoteData.at(op); + // References: a SaplingNoteData copy deep-copies the note's witness list. + const OutputDescription& output = this->vShieldedOutput[op.n]; + const SaplingNoteData& nd = ndIt->second; auto maybe_pt = SaplingNotePlaintext::decrypt( output.encCiphertext,