From e0a4876f3f4bfdba9aebfd51b1f531e7b1ffb095 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Wed, 2 Oct 2024 17:08:46 +0300 Subject: [PATCH] add explicit block fields total size limit - 240 bytes --- src/content/ContentLoader.cpp | 7 +++++++ src/voxels/Block.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index 33b0cf4a..7adb8d3b 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -255,6 +255,13 @@ void ContentLoader::loadBlock( if (root.has("fields")) { def.dataStruct = std::make_unique(); def.dataStruct->deserialize(root["fields"]); + if (def.dataStruct->size() > MAX_BLOCK_FIELDS_SIZE) { + throw std::runtime_error( + util::quote(def.name) + + " fields total size exceeds limit (" + + std::to_string(def.dataStruct->size()) + "/" + + std::to_string(MAX_BLOCK_FIELDS_SIZE) + ")"); + } } if (def.tickInterval == 0) { diff --git a/src/voxels/Block.hpp b/src/voxels/Block.hpp index 4cbbe394..555d0f05 100644 --- a/src/voxels/Block.hpp +++ b/src/voxels/Block.hpp @@ -26,6 +26,8 @@ inline constexpr uint FACE_PZ = 5; /// complex hitboxes inline constexpr uint BLOCK_AABB_GRID = 16; +inline constexpr size_t MAX_BLOCK_FIELDS_SIZE = 240; + inline std::string DEFAULT_MATERIAL = "base:stone"; struct block_funcs_set {