From b32999cee8e6f184e15264d0b4b8f93e8213d334 Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Wed, 8 Feb 2023 06:03:54 -0500 Subject: [PATCH] max indexed tag size --- src/constants.h | 1 + src/events.cpp | 10 ++++++---- src/events.h | 1 - src/filters.h | 6 +++--- src/global.h | 3 +++ src/onAppStartup.cpp | 2 -- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/constants.h b/src/constants.h index 6cd8bca..b331055 100644 --- a/src/constants.h +++ b/src/constants.h @@ -3,3 +3,4 @@ const uint64_t CURR_DB_VERSION = 1; const size_t MAX_SUBID_SIZE = 71; // Statically allocated size in SubId const uint64_t MAX_TIMESTAMP = 17179869184; // Safety limit to ensure it can fit in quadrable key. Good until year 2514. +const size_t MAX_INDEXED_TAG_VAL_SIZE = 255; diff --git a/src/events.cpp b/src/events.cpp index 758c61c..78455f2 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -40,10 +40,12 @@ std::string nostrJsonToFlat(const tao::json::value &v) { } else { if (tagVal.size() < 1 || tagVal.size() > cfg().events__maxTagValSize) throw herr("tag val too small/large: ", tagVal.size()); - tagsGeneral.emplace_back(NostrIndex::CreateTagGeneral(builder, - (uint8_t)tagName[0], - builder.CreateVector((uint8_t*)tagVal.data(), tagVal.size()) - )); + if (tagVal.size() <= MAX_INDEXED_TAG_VAL_SIZE) { + tagsGeneral.emplace_back(NostrIndex::CreateTagGeneral(builder, + (uint8_t)tagName[0], + builder.CreateVector((uint8_t*)tagVal.data(), tagVal.size()) + )); + } } } diff --git a/src/events.h b/src/events.h index c05ce08..21f839b 100644 --- a/src/events.h +++ b/src/events.h @@ -5,7 +5,6 @@ #include "golpe.h" #include "Decompressor.h" -#include "constants.h" diff --git a/src/filters.h b/src/filters.h index c81c954..0363749 100644 --- a/src/filters.h +++ b/src/filters.h @@ -2,8 +2,6 @@ #include "golpe.h" -#include "constants.h" - struct FilterSetBytes { struct Item { @@ -18,6 +16,8 @@ struct FilterSetBytes { // Sizes are post-hex decode FilterSetBytes(const tao::json::value &arrHex, bool hexDecode, size_t minSize, size_t maxSize) { + if (maxSize > MAX_INDEXED_TAG_VAL_SIZE) throw herr("maxSize bigger than max indexed tag size"); + std::vector arr; for (const auto &i : arrHex.get_array()) { @@ -145,7 +145,7 @@ struct NostrFilter { if (tag == 'p' || tag == 'e') { tags.emplace(tag, FilterSetBytes(v, true, 32, 32)); } else { - tags.emplace(tag, FilterSetBytes(v, false, 1, cfg().events__maxTagValSize)); + tags.emplace(tag, FilterSetBytes(v, false, 1, MAX_INDEXED_TAG_VAL_SIZE)); } } else { throw herr("unindexed tag filter"); diff --git a/src/global.h b/src/global.h index da202a5..ce7a282 100644 --- a/src/global.h +++ b/src/global.h @@ -13,3 +13,6 @@ quadrable::Quadrable getQdbInstance(); std::string renderIP(std::string_view ipBytes); + + +#include "constants.h" diff --git a/src/onAppStartup.cpp b/src/onAppStartup.cpp index 6127a1f..c63db6d 100644 --- a/src/onAppStartup.cpp +++ b/src/onAppStartup.cpp @@ -5,8 +5,6 @@ #include "golpe.h" -#include "constants.h" - static void dbCheck(lmdb::txn &txn, const std::string &cmd) { auto dbTooOld = [&](uint64_t ver) {