mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-03 08:46:46 +00:00
refactor: Use named constant for leaf item size (#39)
This commit is contained in:
committed by
Ed Hennis
parent
066e3956fe
commit
bc168453dd
@@ -41,6 +41,9 @@ static constexpr unsigned char const wireTypeInner = 2;
|
||||
static constexpr unsigned char const wireTypeCompressedInner = 3;
|
||||
static constexpr unsigned char const wireTypeTransactionWithMeta = 4;
|
||||
|
||||
// Lower-bound sanity check for SHAMap leaf payloads.
|
||||
inline constexpr std::size_t minSHAMapItemBytes = 12;
|
||||
|
||||
enum class SHAMapNodeType {
|
||||
tnINNER = 1,
|
||||
tnTRANSACTION_NM = 2, // transaction, no metadata
|
||||
|
||||
@@ -27,7 +27,7 @@ SHAMapLeafNode::SHAMapLeafNode(
|
||||
: SHAMapTreeNode(cowid), item_(std::move(item))
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
item_->size() >= 12,
|
||||
item_->size() >= minSHAMapItemBytes,
|
||||
"ripple::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
|
||||
"SHAMapItem const>, std::uint32_t) : minimum input size");
|
||||
}
|
||||
@@ -39,7 +39,7 @@ SHAMapLeafNode::SHAMapLeafNode(
|
||||
: SHAMapTreeNode(cowid, hash), item_(std::move(item))
|
||||
{
|
||||
XRPL_ASSERT(
|
||||
item_->size() >= 12,
|
||||
item_->size() >= minSHAMapItemBytes,
|
||||
"ripple::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
|
||||
"SHAMapItem const>, std::uint32_t, SHAMapHash const&) : minimum input "
|
||||
"size");
|
||||
|
||||
@@ -38,6 +38,12 @@ SHAMapTreeNode::makeTransaction(
|
||||
SHAMapHash const& hash,
|
||||
bool hashValid)
|
||||
{
|
||||
if (data.size() < minSHAMapItemBytes)
|
||||
Throw<std::runtime_error>(
|
||||
"Short TXN node: " + std::to_string(data.size()) +
|
||||
" bytes (minimum " + std::to_string(minSHAMapItemBytes) +
|
||||
" required)");
|
||||
|
||||
auto item =
|
||||
make_shamapitem(sha512Half(HashPrefix::transactionID, data), data);
|
||||
|
||||
@@ -68,6 +74,12 @@ SHAMapTreeNode::makeTransactionWithMeta(
|
||||
|
||||
s.chop(tag.bytes);
|
||||
|
||||
if (s.size() < minSHAMapItemBytes)
|
||||
Throw<std::runtime_error>(
|
||||
"Short TXN+MD node: " + std::to_string(s.size()) +
|
||||
" bytes after tag removal (minimum " +
|
||||
std::to_string(minSHAMapItemBytes) + " required)");
|
||||
|
||||
auto item = make_shamapitem(tag, s.slice());
|
||||
|
||||
if (hashValid)
|
||||
@@ -100,6 +112,12 @@ SHAMapTreeNode::makeAccountState(
|
||||
if (tag.isZero())
|
||||
Throw<std::runtime_error>("Invalid AS node");
|
||||
|
||||
if (s.size() < minSHAMapItemBytes)
|
||||
Throw<std::runtime_error>(
|
||||
"Short AS node: " + std::to_string(s.size()) +
|
||||
" bytes after tag removal (minimum " +
|
||||
std::to_string(minSHAMapItemBytes) + " required)");
|
||||
|
||||
auto item = make_shamapitem(tag, s.slice());
|
||||
|
||||
if (hashValid)
|
||||
|
||||
Reference in New Issue
Block a user