NewLife/X

MaxSafeArraySize
智能大石头 authored at 2026-02-04 16:57:35
982c9d4
Tree
1 Parent(s) 4425eca
Summary: 1 changed files with 3 additions and 0 deletions.
Modified +3 -0
Modified +3 -0
diff --git a/NewLife.Core/Serialization/Binary/BinaryGeneral.cs b/NewLife.Core/Serialization/Binary/BinaryGeneral.cs
index 5ebe1e7..6b3f8e5 100644
--- a/NewLife.Core/Serialization/Binary/BinaryGeneral.cs
+++ b/NewLife.Core/Serialization/Binary/BinaryGeneral.cs
@@ -631,6 +631,9 @@ public class BinaryGeneral : BinaryHandlerBase
         if (!Host.TryReadSize(out var n)) return false;
         if (n <= 0) return true;
 
+        var max = IOHelper.MaxSafeArraySize;
+        if (n > max) throw new XException("Security required, reading large variable length arrays is not allowed {0:n0}>{1:n0}", n, max);
+
 #if NETCOREAPP || NETSTANDARD2_1
         // 栈分配阈值:避免大字符串导致栈溢出
         const Int32 STACK_ALLOC_THRESHOLD = 512;