From 9628177698b29488965bffc60fa305e752245c13 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Sun, 1 Mar 2026 21:46:43 +0300 Subject: [PATCH] fix: missing extended block size limit check --- src/constants.hpp | 2 ++ src/content/loading/BlockLoader.cpp | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/constants.hpp b/src/constants.hpp index 501c5f62e..3ec66c259 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -33,6 +33,8 @@ inline constexpr int CHUNK_W = 16; inline constexpr int CHUNK_H = 256; inline constexpr int CHUNK_D = 16; +inline constexpr int EXTENDED_BLOCK_LIMIT = CHUNK_W; // must not be greater than chunk width and depth + inline constexpr uint VOXEL_USER_BITS = 8; inline constexpr uint VOXEL_USER_BITS_OFFSET = sizeof(blockstate_t)*8-VOXEL_USER_BITS; diff --git a/src/content/loading/BlockLoader.cpp b/src/content/loading/BlockLoader.cpp index 87c10fa67..3bacf9d9f 100644 --- a/src/content/loading/BlockLoader.cpp +++ b/src/content/loading/BlockLoader.cpp @@ -12,6 +12,7 @@ #include "presets/ParticlesPreset.hpp" #include "util/stringutil.hpp" #include "voxels/Block.hpp" +#include "constants.hpp" using namespace data; @@ -184,7 +185,11 @@ template<> void ContentUnitLoader::loadUnit( if (auto found = root.at("emission")) { const auto& emissionarr = *found; for (size_t i = 0; i < 3; i++) { - def.emission[i] = glm::clamp(emissionarr[i].asInteger(), static_cast(0), static_cast(15)); + def.emission[i] = glm::clamp( + emissionarr[i].asInteger(), + static_cast(0), + static_cast(15) + ); } } @@ -199,7 +204,16 @@ template<> void ContentUnitLoader::loadUnit( "block " + util::quote(def.name) + ": invalid block size" ); } - + + if (def.size.x > EXTENDED_BLOCK_LIMIT || + def.size.y > EXTENDED_BLOCK_LIMIT || + def.size.z > EXTENDED_BLOCK_LIMIT) { + throw std::runtime_error( + "extended block " + util::quote(def.name) + " size limit " + + std::to_string(EXTENDED_BLOCK_LIMIT) + " exceeded" + ); + } + // should variant modify hitbox? if (def.defaults.model.type == BlockModelType::BLOCK && (def.size.x != 1 || def.size.y != 1 || def.size.z != 1)) {