From 6546d17414cd6b54a518157ed1f8febd3479d7f7 Mon Sep 17 00:00:00 2001 From: levoncrypto Date: Mon, 11 Nov 2024 09:23:01 +0400 Subject: [PATCH] Add additional checks for memo --- src/qt/sendcoinsentry.cpp | 4 +++- src/spark/primitives.h | 10 +++++++++- src/spark/sparkwallet.cpp | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/qt/sendcoinsentry.cpp b/src/qt/sendcoinsentry.cpp index 4697423868..1427b1c76d 100644 --- a/src/qt/sendcoinsentry.cpp +++ b/src/qt/sendcoinsentry.cpp @@ -11,6 +11,7 @@ #include "optionsmodel.h" #include "platformstyle.h" #include "walletmodel.h" +#include "../spark/sparkwallet.h" #include "../wallet/wallet.h" #include @@ -70,7 +71,8 @@ SendCoinsEntry::~SendCoinsEntry() void SendCoinsEntry::on_MemoTextChanged(const QString &text) { - int maxLength = 256; + const spark::Params* params = spark::Params::get_default(); + int maxLength = params->get_memo_bytes(); bool isOverLimit = text.length() > maxLength; if (isOverLimit) { diff --git a/src/spark/primitives.h b/src/spark/primitives.h index 09de4550eb..2bfa0c72bb 100644 --- a/src/spark/primitives.h +++ b/src/spark/primitives.h @@ -107,7 +107,15 @@ class CSparkOutputTx inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(address); READWRITE(amount); - READWRITE(memo); + if (ser_action.ForRead()) { + if (!s.empty()) { + READWRITE(memo); + } else { + memo = ""; + } + } else { + READWRITE(memo); + } } }; diff --git a/src/spark/sparkwallet.cpp b/src/spark/sparkwallet.cpp index d99a3f4810..6b3b421bda 100644 --- a/src/spark/sparkwallet.cpp +++ b/src/spark/sparkwallet.cpp @@ -743,6 +743,10 @@ std::vector CSparkWallet::CreateSparkMintRecipients( unsigned char network = spark::GetNetworkType(); std::string addr = outputs[i].address.encode(network); std::string memo = outputs[i].memo; + const std::size_t max_memo_size = outputs[i].address.get_params()->get_memo_bytes(); + if (memo.length() > max_memo_size) { + throw std::runtime_error("Memo exceeds maximum length"); + } CRecipient recipient = {script, CAmount(outputs[i].v), false, addr, memo}; results.emplace_back(recipient); }