Files
opengenesislinkserver/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/MeshUploadIndexGuard.cs
T
OpenGenesis (MPL 2.0) cffd8469f5 Fix CAPS mesh upload array bounds and malformed instance handling (#449)
Fix instance/mesh side-index mismatch in Mesh CAPS upload; validate mesh references and root objects, ensure safe viewer failure and state reset. Add .NET 10 regression and CI gate. No change to HGSP2 or optional S3 features.
2026-11-16 16:51:07 +01:00

36 lines
1.3 KiB
C#

// SPDX-License-Identifier: MPL-2.0
#nullable enable
using System;
namespace OpenSim.Region.ClientStack.Linden
{
/// <summary>
/// Bounds-check the mesh index supplied by each uploaded instance.
/// Instances and meshes are different lists: many instances may refer
/// to a single mesh. The mesh sides lookup MUST use meshIndex, never
/// the index in instance_list.
/// </summary>
public static class MeshUploadIndexGuard
{
public static bool TryResolveSides(int meshIndex, int meshCount,
int[]? meshSides, int instanceFaceCount, out int sides)
{
sides = 0;
if (meshIndex < 0 || meshIndex >= meshCount || meshCount < 1)
return false;
// Older or custom viewers may send a missing/short fee-side
// array. In that case use the instance's face count, as before.
// At least one face is needed when constructing the prim shape.
sides = meshSides != null && meshIndex < meshSides.Length &&
meshSides[meshIndex] > 0
? meshSides[meshIndex]
: Math.Max(1, instanceFaceCount);
return true;
}
public static bool HasRenderableRoot(int renderableInstanceCount)
=> renderableInstanceCount > 0;
}
}