fix(g1/data): PBR-Preflight und SQL-Mitgliedschaftsabfragen (#425)

* fix(pbr): preflight all requested glTF overrides before changing any face assets

* fix(groups): implement principal membership queries for SQL backends

* fix(groups): implement principal membership queries for SQL backends

* fix(pbr): validate factor vector length and finite glTF color values before commit

* test(pbr): reject invalid factor vectors before a material write

* docs(data): narrow PBR and SQL membership integrity scope with E2E gates

* ci(g1): run Regression-test PBR atomic material preflight before optional native dependencies
This commit is contained in:
OpenGenesis (MPL 2.0) authored and GitHub committed 2026-11-11 17:46:00 +01:00
1 parent 429fd8a19f
commit c7cf5b21ef
6 files changed
+153 -14

No files matched your search

+3
View File
@@ -45,6 +45,9 @@ jobs:
- name: Regression-test G1 performance sampling and bounded multicore job queue
run: dotnet run --configuration Release --project tools/ci/OglPerformanceEngineRegression/OglPerformanceEngineRegression.csproj
- name: Regression-test PBR atomic material preflight
run: dotnet run --configuration Release --project tools/ci/OglPbrMaterialRegression/OglPbrMaterialRegression.csproj
- name: Verify isolated .NET 10 ROBUST runtime on Linux x64
run: |
python3 tools/gen11/robust_runtime_smoke.py
+13 -4
View File
@@ -345,13 +345,22 @@ namespace OpenSim.Data.MySQL
#region combinations
public MembershipData RetrievePrincipalGroupMembership(string principalID, UUID groupID)
{
// TODO
return null;
if (string.IsNullOrWhiteSpace(principalID) || groupID.IsZero())
return null;
MembershipData[] matches = m_Membership.Get(
new[] { "GroupID", "PrincipalID" },
new[] { groupID.ToString(), principalID });
return matches is { Length: > 0 } ? matches[0] : null;
}
public MembershipData[] RetrievePrincipalGroupMemberships(string principalID)
{
// TODO
return null;
if (string.IsNullOrWhiteSpace(principalID))
return Array.Empty<MembershipData>();
return m_Membership.Get("PrincipalID", principalID) ??
Array.Empty<MembershipData>();
}
#endregion
+13 -4
View File
@@ -350,13 +350,22 @@ namespace OpenSim.Data.PGSQL
#region combinations
public MembershipData RetrievePrincipalGroupMembership(string principalID, UUID groupID)
{
// TODO
return null;
if (string.IsNullOrWhiteSpace(principalID) || groupID.IsZero())
return null;
MembershipData[] matches = m_Membership.Get(
new[] { "GroupID", "PrincipalID" },
new[] { groupID.ToString(), principalID });
return matches is { Length: > 0 } ? matches[0] : null;
}
public MembershipData[] RetrievePrincipalGroupMemberships(string principalID)
{
// TODO
return null;
if (string.IsNullOrWhiteSpace(principalID))
return Array.Empty<MembershipData>();
return m_Membership.Get("PrincipalID", principalID) ??
Array.Empty<MembershipData>();
}
#endregion
@@ -912,6 +912,30 @@ namespace OpenSim.Region.OptionalModules.Materials
OSDArray req = (OSDArray)OSDParser.DeserializeLLSDXml(httpRequest.InputStream);
httpRequest.InputStream.Dispose();
if (req.Count > m_maxMaterialsPerTransaction)
throw new FormatException("Too many PBR material changes in one request");
// Preflight every authorized, applicable glTF override before
// mutating any face in this request. Invalid factor/vector
// lengths, indices or JSON must not leave new asset IDs behind.
foreach (OSD candidate in req)
{
if (candidate is not OSDMap candidateMap)
throw new FormatException("PBR material change must be a map");
if (!candidateMap.TryGetValue("object_id", out OSD rawObjectId) ||
!candidateMap.TryGetValue("side", out OSD rawSide) ||
!TryParseMaterialSide(rawSide, out int candidateSide) ||
!candidateMap.TryGetValue("gltf_json", out OSD rawGltf))
continue;
SceneObjectPart target = m_scene.GetSceneObjectPart(rawObjectId.AsUUID());
if (target is null || target.Shape is null ||
!m_scene.Permissions.CanEditObject(target.UUID, agentID))
continue;
string gltf = rawGltf.AsString().TrimEnd('\n');
if (gltf.Length > 0 && !CanApplyMaterialOverride(gltf, candidateSide))
throw new FormatException("Invalid PBR glTF override");
}
OSD tmp;
HashSet<SceneObjectPart> changedSOPs = new();
@@ -1104,6 +1128,20 @@ namespace OpenSim.Region.OptionalModules.Materials
transforms[channel] = transform;
}
private static OSDArray RequireFiniteColorFactor(OSD value, int components)
{
if (value is not OSDArray values || values.Count != components)
throw new FormatException("Invalid glTF color factor length");
foreach (OSD component in values)
{
if ((component is not OSDReal && component is not OSDInteger) ||
!double.IsFinite(component.AsReal()) ||
component.AsReal() < 0 || component.AsReal() > 1)
throw new FormatException("Invalid glTF color factor component");
}
return values;
}
private static OSDArray RequireFiniteVector2(OSD value)
{
if (value is not OSDArray items || items.Count != 2)
@@ -1160,6 +1198,15 @@ namespace OpenSim.Region.OptionalModules.Materials
return true;
}
// Probe conversion against a private temporary array. The converter
// never sees any live face state; false means invalid glTF or an
// unsupported/empty override, never a partially committed asset ID.
private static bool CanApplyMaterialOverride(string data, int side)
{
RenderMaterialOverrideEntry[] scratch = null;
return AddMaterialOverride(ref scratch, data, side);
}
private static bool AddMaterialOverride(ref RenderMaterialOverrideEntry[] overrides, string data, int side)
{
if (side < 0 || side > byte.MaxValue)
@@ -1263,8 +1310,9 @@ namespace OpenSim.Region.OptionalModules.Materials
}
SetTextureTransform(ti, 2, pmrMapmrt);
}
if (pmrMap.TryGetValue("baseColorFactor", out tmposd) && tmposd is OSDArray baseColorFactor)
if (pmrMap.TryGetValue("baseColorFactor", out tmposd))
{
OSDArray baseColorFactor = RequireFiniteColorFactor(tmposd, 4);
outosd["bc"] = new OSDArray()
{
Math.Round((double) baseColorFactor[0], 4),
@@ -1273,13 +1321,15 @@ namespace OpenSim.Region.OptionalModules.Materials
Math.Round((double) baseColorFactor[3], 4)
};
}
if (pmrMap.TryGetValue("metallicFactor", out tmposd) && tmposd is OSDReal metallicFactor)
if (pmrMap.TryGetValue("metallicFactor", out tmposd))
{
outosd["mf"] = Math.Round((double)metallicFactor, 3);
OSDArray factor = RequireFiniteColorFactor(new OSDArray { tmposd }, 1);
outosd["mf"] = Math.Round(factor[0].AsReal(), 3);
}
if (pmrMap.TryGetValue("roughnessFactor", out tmposd) && tmposd is OSDReal roughnessFactor)
if (pmrMap.TryGetValue("roughnessFactor", out tmposd))
{
outosd["rf"] = Math.Round((double)roughnessFactor, 3);
OSDArray factor = RequireFiniteColorFactor(new OSDArray { tmposd }, 1);
outosd["rf"] = Math.Round(factor[0].AsReal(), 3);
}
}
@@ -1363,8 +1413,9 @@ namespace OpenSim.Region.OptionalModules.Materials
outosd["ac"] = Math.Round((double)alphaCutoff, 3);
}
if (material.TryGetValue("emissiveFactor", out tmposd) && tmposd is OSDArray emissiveFactor)
if (material.TryGetValue("emissiveFactor", out tmposd))
{
OSDArray emissiveFactor = RequireFiniteColorFactor(tmposd, 3);
outosd["ec"] = new OSDArray()
{
Math.Round((double) emissiveFactor[0], 4),
@@ -0,0 +1,44 @@
# G1 Datenintegritaet – PBR/CAPS und Gruppenabfragen
Stand: 2026-11-11. Dieser Change ist ein **Code-Fix**, keine produktive
Datenbankmigration oder ein automatischer Versions-Rollout.
## PBR – Mutation erst nach Preflight
`MaterialsModule.ModifyMaterialParams` prueft eine begrenzte Zahl an
Materialaenderungen schon **vor** der ersten Objektmutation. Ungueltige
glTF-JSON-Overrides (Laenge, Typ, Grenzwert oder Texturindex) werden abgewiesen;
sie duerfen kein zuvor gueltiges `asset_id` hinterlassen. Fuer ein Gesicht
bleibt die vorhandene RenderMaterial-Struktur kompatibel.
Die Vorsondierung nimmt nur Objekte, fuer die die Viewer-Capability
Editierberechtigung besitzt. Damit werden unberechtigte Objekte weiterhin
uebergangen. Der glTF-Konverter prueft nun insbesondere
`baseColorFactor` (4 Werte), `emissiveFactor` (3 Werte),
`metallicFactor` und `roughnessFactor` (je 1 Wert) auf endliche,
numerische Komponenten von 0 bis 1.
**Abnahme**: `OglPbrMaterialRegression` plus echter Firestorm-Test mit
berechtigtem und unberechtigtem Objekt, Materialwechsel,
negativem Face-Index, erst gueltigem dann ungueltigem Request-Element,
Regionwechsel, Relog und SQL-Roundtrip. Die CAP ist weiterhin kein
vollstaendiger glTF-/GLB-Modellimport.
## Gruppen – bislang leere SQL-Methoden
`RetrievePrincipalGroupMembership` und
`RetrievePrincipalGroupMemberships` geben fuer MySQL/MariaDB
und PostgreSQL nicht mehr immer `null` zurueck, sondern fragen
die vorhandenen Membership-Tabellen ab. Ungueltige IDs ergeben
`null` bzw. ein leeres Array.
Kein Schemaeingriff, keine In-Place-Datenmigration. Die aelteren
`GetGroupRoles`-Berechtigungsfragen gehoeren in ein eigenes Security-Gate.
## Ausdruecklich nicht integriert
PR #414 umfasst separate PostgreSQL-Estate-/Profiltransaktionen.
Die bestehende Passwort-Recovery / Portal-Migration und die
FSAssets/OGL AssetService-Migration benoetigen isolierte
End-to-End-Abnahmen. Diese Arbeiten werden nicht nebenbei auf
einem produktiven Datenbestand durchgefuehrt.
@@ -131,6 +131,29 @@ internal static class Program
Assert(overrideEntries.Length == 1 && overrideEntries[0].data == serialized,
"malformed glTF material mutated prior state");
// The live ModifyMaterialParams handler preflights each glTF
// candidate before modifying the shape's asset_id. This validation
// must accept legitimate factors while rejecting malformed vectors.
var preflight = typeof(MaterialsModule).GetMethod("CanApplyMaterialOverride",
BindingFlags.NonPublic | BindingFlags.Static);
Assert(preflight != null, "PBR atomic preflight helper missing");
Assert((bool)preflight.Invoke(null, new object[] { gltf, 4 }),
"valid PBR material must pass no-mutation preflight");
foreach (string malformed in new[]
{
"{\"materials\":[{\"pbrMetallicRoughness\":{\"baseColorFactor\":[1,0,0]}}]}",
"{\"materials\":[{\"pbrMetallicRoughness\":{\"baseColorFactor\":[1,0,0,1,0]}}]}",
"{\"materials\":[{\"pbrMetallicRoughness\":{\"baseColorFactor\":[1,0,\"bad\",1]}}]}",
"{\"materials\":[{\"pbrMetallicRoughness\":{\"metallicFactor\":-1}}]}",
"{\"materials\":[{\"pbrMetallicRoughness\":{\"roughnessFactor\":2}}]}",
"{\"materials\":[{\"emissiveFactor\":[0.1,0.2]}]}",
"{\"materials\":[{\"emissiveFactor\":[0.1,0.2,1.1]}]}"
})
{
Assert(!(bool)preflight.Invoke(null, new object[] { malformed, 4 }),
"invalid glTF factor changed would-be PBR mutation preflight");
}
// LLSD side indices are byte encoded. Negative, overflowing and
// non-integer values must not alias another user's material face.
Assert(ParseSide(OSD.FromInteger(0), out int parsedSide) && parsedSide == 0,