From 6f0e46a25aa06ad13ddd484100cd014a5ad5785e Mon Sep 17 00:00:00 2001 From: "OpenGenesis (MPL 2.0)" <153564363+opengenesislink@users.noreply.github.com> Date: Wed, 4 Nov 2026 18:12:38 +0100 Subject: [PATCH] fix(net10): use exact stream reads and modern X509CertificateLoader --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- .../Servers/HttpServer/OSHttpServer/HttpRequest.cs | 12 +++++++++++- OpenSim/Framework/Util.cs | 4 ++-- .../World/Estate/EstateManagementModule.cs | 2 +- .../DataSnapshot/DataSnapshotManager.cs | 10 +++++----- .../AuthenticationServerPostHandler.cs | 10 +++++----- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 141a64a6..9fa9d325 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -217,7 +217,7 @@ namespace OpenSim.Framework.Servers.HttpServer { try { - m_cert = new X509Certificate2(CPath, CPass); + m_cert = X509CertificateLoader.LoadPkcs12FromFile(CPath, CPass); X509Extension ext = m_cert.Extensions["2.5.29.17"]; if(ext != null) { diff --git a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs index d0ed6677..1907f059 100644 --- a/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs +++ b/OpenSim/Framework/Servers/HttpServer/OSHttpServer/HttpRequest.cs @@ -235,7 +235,17 @@ namespace OSHttpServer } var buffer = new byte[m_body.Length]; - m_body.Read(buffer, 0, (int)m_body.Length); + // Preserve the original request stream position while cloning its full body. + long originalPosition = m_body.Position; + try + { + m_body.Position = 0; + m_body.ReadExactly(buffer); + } + finally + { + m_body.Position = originalPosition; + } request.Body = new MemoryStream(); request.Body.Write(buffer, 0, buffer.Length); request.Body.Seek(0, SeekOrigin.Begin); diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 08f1ccc5..ada382e6 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -2581,7 +2581,7 @@ namespace OpenSim.Framework memory.Position = 0; using GZipStream decompressor = new(memory, CompressionMode.Decompress); - decompressor.Read(buffer, 0, buffer.Length); + decompressor.ReadExactly(buffer); return Util.UTF8.GetString(buffer); } @@ -2884,7 +2884,7 @@ namespace OpenSim.Framework public static OSDMap GetOSDMap(Stream stream, int length) { byte[] data = new byte[length]; - stream.Read(data, 0, length); + stream.ReadExactly(data); string strdata = Util.UTF8.GetString(data); OSDMap args; OSD buffer; diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index 2cd458ea..677dd2ad 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs @@ -1426,7 +1426,7 @@ namespace OpenSim.Region.CoreModules.World.Estate using(FileStream input = new FileStream(Util.dataDir() + "/terrain.raw",FileMode.Open)) { bdata = new byte[input.Length]; - input.Read(bdata, 0, (int)input.Length); + input.ReadExactly(bdata); } if(bdata == null || bdata.Length == 0) { diff --git a/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs b/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs index 6f9484a0..14a63c46 100644 --- a/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs +++ b/OpenSim/Region/OptionalModules/DataSnapshot/DataSnapshotManager.cs @@ -398,7 +398,6 @@ namespace OpenSim.Region.DataSnapshot #region External data services private void NotifyDataServices(string servicesStr, string serviceName) { - Stream reply = null; string delimStr = ";"; char [] delimiter = delimStr.ToCharArray(); @@ -416,10 +415,11 @@ namespace OpenSim.Region.DataSnapshot cli.RequestMethod = "GET"; try { - using(reply = cli.Request(null)) + // The notification response body is not used. Disposing the + // response stream is sufficient; do not require a fixed + // response length from third-party services. + using (Stream reply = cli.Request(null)) { - byte[] response = new byte[1024]; - reply.Read(response, 0, 1024); } } catch (HttpRequestException) @@ -433,7 +433,7 @@ namespace OpenSim.Region.DataSnapshot // This is not quite working, so... // string responseStr = Util.UTF8.GetString(response); - m_log.Info("[DATASNAPSHOT]: data service " + url + " notified. Secret: " + m_Secret); + m_log.Info("[DATASNAPSHOT]: data service " + url + " notified."); } } } diff --git a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs index 3455229b..746d465a 100644 --- a/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs +++ b/OpenSim/Server/Handlers/Authentication/AuthenticationServerPostHandler.cs @@ -88,11 +88,11 @@ namespace OpenSim.Server.Handlers.Authentication return DoPlainMethods(body); case "crypt": - byte[] buffer = new byte[request.Length]; - long length = request.Length; - if (length > 16384) - length = 16384; - request.Read(buffer, 0, (int)length); + // Encrypted requests have a strict 16 KiB processing limit. + // Allocate only the bytes that are actually consumed. + int length = checked((int)Math.Min(request.Length, 16384L)); + byte[] buffer = new byte[length]; + request.ReadExactly(buffer); return DoEncryptedMethods(buffer); }