From 69a6d6a02ce360b9fd5518fed03e09aed6e68225 Mon Sep 17 00:00:00 2001
From: Rolo <roloedits@gmail.com>
Date: Tue, 11 Jun 2024 11:24:09 -0700
Subject: [PATCH] fix(editor): prevent overflow in count modifier

---
 helix-term/src/ui/editor.rs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index d584afbb005a..a071bfaa8138 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -938,7 +938,11 @@ impl EditorView {
             // If the count is already started and the input is a number, always continue the count.
             (key!(i @ '0'..='9'), Some(count)) => {
                 let i = i.to_digit(10).unwrap() as usize;
-                cxt.editor.count = NonZeroUsize::new(count.get() * 10 + i);
+                let count = count.get() * 10 + i;
+                if count > 100_000_000 {
+                    return;
+                }
+                cxt.editor.count = NonZeroUsize::new(count);
             }
             // A non-zero digit will start the count if that number isn't used by a keymap.
             (key!(i @ '1'..='9'), None) if !self.keymaps.contains_key(mode, event) => {