fix(yengine): reject incompatible migration headers before atomically installing imported state

This commit is contained in:
OpenGenesis (MPL 2.0) committed 2026-11-07 21:02:43 +01:00
1 parent 3f7af292c9
commit 4e42d0cf0d
4 files changed
+27 -5

No files matched your search

@@ -1223,7 +1223,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine
return false;
try
{
Convert.FromBase64String(snapshotN.InnerText);
byte[] migration = Convert.FromBase64String(snapshotN.InnerText);
// The first byte is YEngine's explicit migration version.
// Reject definitely incompatible OAR data before replacing
// an existing .state file. Full object-graph validation
// still requires the matching compiled script on staging.
if (migration.Length < 3 ||
migration[0] != XMRInstance.migrationVersion)
return false;
}
catch (FormatException)
{
@@ -106,3 +106,10 @@ Legacy XEngine imports retain their distinct Variables-based format.
Script timers are not changed until the YEngine binary snapshot was
decoded successfully. No automatic historic graph execution is enabled.
Import preflight also rejects YEngine snapshot headers whose migration version
does not match `XMRInstance.migrationVersion`. This protects existing state
files from obviously incompatible payloads; it **does not** prove that the
remaining object graph is valid or compatible. Only a controlled staged
restore with its compiled script can establish that. No unsafe object
deserialization is used in preflight.
@@ -237,10 +237,17 @@ try
Check(File.ReadAllText(importedPath) == beforeImport,
"oversized OAR XML left saved state unchanged");
Check(engine.SetXMLState(stateId, importPrefix + "AQID" + importSuffix),
"valid bounded YEngine OAR state imported");
Check(File.ReadAllText(importedPath).Contains("<Snapshot>AQID</Snapshot>"),
"valid OAR state atomically installed");
Check(!engine.SetXMLState(stateId, importPrefix + "AQID" + importSuffix),
"unsupported YEngine migration version rejected before import");
Check(File.ReadAllText(importedPath) == beforeImport,
"unknown-version OAR state did not overwrite existing state");
string matchingHeader = Convert.ToBase64String(
new byte[] { XMRInstance.migrationVersion, 16, 0 });
Check(engine.SetXMLState(stateId, importPrefix + matchingHeader + importSuffix),
"bounded YEngine OAR header imported without full script decoding");
Check(File.ReadAllText(importedPath).Contains(
"<Snapshot>" + matchingHeader + "</Snapshot>"),
"matching-header OAR state atomically installed");
Check(Directory.GetFiles(Path.GetDirectoryName(importedPath)!).Length == 1,
"OAR importer left no temporary files");
@@ -34,6 +34,7 @@ assert "doc = XMRInstance.ParsePersistedStateXml(xml)" in engine
assert "XMRInstance.WriteStateFileAtomically(statePath, scriptStateN.OuterXml)" in engine
assert "using (FileStream ss = File.Create(statePath))" not in engine
assert "Convert.FromBase64String(snapshotN.InnerText)" in engine
assert "migration[0] != XMRInstance.migrationVersion" in engine
assert "restoredScriptTime.HasValue" in ctor
assert "DtdProcessing = DtdProcessing.Prohibit" in capture
assert "File.Move(temporary, statePath, overwrite: true)" in capture