From e5232606f464e4a78f53b7ca5e071d44f6739591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20Gul=C3=A1csi?= Date: Sun, 12 Nov 2023 14:27:11 +0100 Subject: [PATCH] hungarian: fix panic in stem1, stem5 (length check) --- hungarian/stem.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hungarian/stem.go b/hungarian/stem.go index d45be08..0c288ad 100644 --- a/hungarian/stem.go +++ b/hungarian/stem.go @@ -94,14 +94,14 @@ func step1(w *snowballword.SnowballWord) { return } // in R1 - if w.R1start > n-2 { + if w.R1start > n-2 || n < 4 { return } // (In the case of consonant plus digraph, such as ccs, remove a c). - if isDoubleConsonant(w.RS[n-5:n-2]) > 2 { + if n >= 5 && isDoubleConsonant(w.RS[n-5:n-2]) > 2 { w.RS[n-5], w.RS[n-4] = w.RS[n-4], w.RS[n-3] w.RemoveLastNRunes(3) - } else if isDoubleConsonant(w.RS[n-4:n-2]) > 1 { + } else if n >= 4 && isDoubleConsonant(w.RS[n-4:n-2]) > 1 { // preceded by a double consonant w.RemoveLastNRunes(3) } @@ -221,7 +221,7 @@ func step5(w *snowballword.SnowballWord) { return } // (In the case of consonant plus digraph, such as ccs, remove a c). - if isDoubleConsonant(w.RS[n-4:n-1]) > 2 { + if n >= 4 && isDoubleConsonant(w.RS[n-4:n-1]) > 2 { w.RS[n-4], w.RS[n-3] = w.RS[n-3], w.RS[n-1] w.RemoveLastNRunes(2) } else if isDoubleConsonant(w.RS[n-3:n-1]) > 1 {