From b2a617362eb836a5e209e79beba8ff3f76435558 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 12 Jul 2026 13:35:15 +0300 Subject: [PATCH 1/2] Fix segfault in lookupMaterialColor from unbounded color index state_color[0] was used directly as an index into descriptors.colors without bounds-checking. Materials with an invalid/out-of-range color index (observed with matIndex=307) caused a segfault instead of falling back to defaultColor. --- ContentLoader.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ContentLoader.cpp b/ContentLoader.cpp index 3f7429a1..d223ac94 100644 --- a/ContentLoader.cpp +++ b/ContentLoader.cpp @@ -743,8 +743,11 @@ ALLEGRO_COLOR lookupMaterialColor(int matType, int matIndex, int dyeType, int dy DFColor: DFHack::MaterialInfo mat; if(mat.decode(matType, matIndex)) { - auto cd = df::global::world->raws.descriptors.colors[mat.material->state_color[0]]; - return al_map_rgb_f(cd->red, cd->green, cd->blue) * dyeColor; + int16_t colorIdx = mat.material->state_color[0]; + if (colorIdx >= 0 && size_t(colorIdx) < df::global::world->raws.descriptors.colors.size()) { + auto cd = df::global::world->raws.descriptors.colors[colorIdx]; + return al_map_rgb_f(cd->red, cd->green, cd->blue) * dyeColor; + } } return defaultColor * dyeColor; } From 0ed936d1ee66cdd14702011f0cfd69fd512550d7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 12 Jul 2026 18:33:38 +0300 Subject: [PATCH 2/2] Add changelog entry --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 5ef44c6d..7ecad818 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -40,6 +40,7 @@ Template for new versions: ## New Features ## Fixes +- `stonesense`: fixed a crash when rendering materials with an out-of-range color index ## Misc Improvements