museglimmer: the vision tower bounds the config it allocates by

MuseTower::declare read vision_config.num_hidden_layers and the position
grid with only a positive check, then handed them to host vectors --
full.assign(depth), L.assign(depth) -- before any weight was consulted.
A container stating 2^62 layers threw std::length_error (or bad_alloc
just below max_size) out of the declare phase, and nothing between there
and main catches: the process died with a SIGABRT and no report, where
every other bad config in this file says what it dislikes on stderr and
refuses with RAD_E_INVAL. The grid sides were the same story multiplied:
pos_emb_height x pos_emb_width is a signed product of container values
that can overflow before any comparison could see it.

The gate now refuses depth past 128 and a grid side past 512, against
published maxima rather than round numbers: the deepest vision encoder
ever shipped is 48 layers (ViT-22B, InternViT-6B -- this family's towers
are SigLIP-class, tens), and the largest stored position table a side of
92 (SigLIP at 1292 px over patch 14; CLIP 16, SAM 64; native-resolution
towers store no side x side table). The caps sit ~2.6x and ~5.5x past
those, so they never bite an honest container, and at the cap itself the
guarded shapes are harmless: the depth vectors cost KiB and the grid
products top out at 2^18, too small to wrap signed 64 before a
comparison sees them. museglimmer_test pins both caps at their boundary
and far past it -- the grid at both sides together, since one side
alone the height==width rule refuses before the cap is consulted.

Found by the 2.1.0 review pass (axis: hostile model files); caps
sourced against published encoders and tightened at the operator's
request, from the first pass's wide 512/4096 margins.
This commit is contained in:
fl0l0u committed 2026-11-15 22:02:26 +00:00
1 parent 4943bba2fb
commit 392746da6b
2 files changed
+35 -4

No files matched your search

+17 -4
View File
@@ -132,11 +132,24 @@ inline int MuseTower::declare(RadBuilder* b, const RadModelMeta* m, const RadBui
proj_ff = rad_meta_geti(m, "projector_hidden_size", 4096);
out_hidden = rad_meta_geti(m, "out_hidden_size", 6144);
n_embd = model_embd;
if (depth <= 0 || width <= 0 || heads <= 0 || ff <= 0 || patch <= 0 || temporal <= 0 ||
merge <= 0 || side <= 0 || proj_ff <= 0 || out_hidden <= 0 || width % heads ||
/* Bounds the walk and the host allocations below take at face value, set against published
* maxima rather than round numbers: the deepest vision encoder ever shipped is 48 layers
* (ViT-22B, InternViT-6B; this family's towers are SigLIP-class, tens), and the largest
* stored position table a side of 92 (SigLIP at 1292 px over patch 14; CLIP 16, SAM 64 --
* native-resolution towers store no side x side table at all). The caps sit ~2.6x and
* ~5.5x past those maxima, so they never bite an honest container, and at the cap the
* guarded shapes are harmless: the depth vectors cost KiB and the grid products reach 2^18
* at most. Past the caps the container is not describing a model but a vector size
* (full.assign(depth) and L.assign(depth) would throw past max_size, and the grid products
* below overflow signed 64 before any comparison could notice). Refuse like every other
* bad config: say so and RAD_E_INVAL. */
if (depth <= 0 || depth > 128 || width <= 0 || heads <= 0 || ff <= 0 || patch <= 0 ||
temporal <= 0 || merge <= 0 || side <= 0 || side > 512 || proj_ff <= 0 ||
out_hidden <= 0 || width % heads ||
rad_meta_geti(m, "vision_config.pos_emb_width", 0) != side) {
fprintf(stderr, "radiance: museglimmer: the container's vision_config is incomplete or "
"inconsistent (depth %lld, hidden %lld, heads %lld, ff %lld, patch %lld, "
fprintf(stderr, "radiance: museglimmer: the container's vision_config is incomplete, "
"inconsistent, or past what this tower walks (depth %lld, hidden %lld, "
"heads %lld, ff %lld, patch %lld, "
"temporal %lld, merge %lld, position grid %lld x %lld, projector %lld, "
"merged %lld)\n", (long long)depth, (long long)width, (long long)heads,
(long long)ff, (long long)patch, (long long)temporal, (long long)merge,
+18
View File
@@ -532,6 +532,12 @@ TEST(museglimmer_refuses_a_vision_tower_it_does_not_serve) {
{ "vision_config.merge_size", "4", RAD_E_UNSUPPORTED },
{ "out_hidden_size", "256", RAD_E_INVAL },
{ "vision_config.pos_emb_width", "8", RAD_E_INVAL },
/* the counts the declare walks and hosts-allocates by: a container naming a layer count
* or grid past what a tower is must refuse, not throw a vector length out of bringup.
* 129 is the first depth the bound refuses; the published maximum is 48. */
{ "vision_config.num_hidden_layers", "129", RAD_E_INVAL },
{ "vision_config.num_hidden_layers", "4611686018427387904", RAD_E_INVAL },
{ "vision_config.pos_emb_height", "4611686018427387904", RAD_E_INVAL },
};
for (const auto& kc : kCases) {
MetaKV mk = with_vision(muse_meta());
@@ -544,6 +550,18 @@ TEST(museglimmer_refuses_a_vision_tower_it_does_not_serve) {
}
}
TEST(museglimmer_refuses_a_position_grid_past_its_bounds) {
/* One key at a time cannot pin the grid bound: pos_emb_height alone the height==width
* rule refuses before the cap is consulted. Both sides together reach it -- 513 is the
* first side the bound refuses, against a published maximum of 92. */
MetaKV mk = with_vision(muse_meta());
mk.set("vision_config.pos_emb_height", "513");
mk.set("vision_config.pos_emb_width", "513");
RadBuilder b;
RadBuildCtx ctx = muse_ctx(0, 1, 64);
CHECK_EQ(stderr_of_rc([&] { return museglimmer::declare(&b, mk.meta(), &ctx); }), RAD_E_INVAL);
}
/* ==================================================================== 5. the encoder step */
/* An encoder pass issues the tower and nothing else, over two 8 x 4 frames (two windows each);