From c735117910e8d6bff6c9ce357011b1a9b6e55d32 Mon Sep 17 00:00:00 2001 From: dsarno Date: Sun, 17 Aug 2025 07:35:51 -0700 Subject: [PATCH] Prevent overflow when counting edit bytes --- UnityMcpBridge/Editor/Tools/ManageScript.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/UnityMcpBridge/Editor/Tools/ManageScript.cs b/UnityMcpBridge/Editor/Tools/ManageScript.cs index 29339604..1324d9b2 100644 --- a/UnityMcpBridge/Editor/Tools/ManageScript.cs +++ b/UnityMcpBridge/Editor/Tools/ManageScript.cs @@ -465,7 +465,7 @@ private static object ApplyTextEdits( // Convert edits to absolute index ranges var spans = new List<(int start, int end, string text)>(); - int totalBytes = 0; + long totalBytes = 0; foreach (var e in edits) { try @@ -483,7 +483,10 @@ private static object ApplyTextEdits( if (eidx < sidx) (sidx, eidx) = (eidx, sidx); spans.Add((sidx, eidx, newText)); - totalBytes += System.Text.Encoding.UTF8.GetByteCount(newText); + checked + { + totalBytes += System.Text.Encoding.UTF8.GetByteCount(newText); + } } catch (Exception ex) {