Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hungarian: fix panic in stem1, stem5 (length check) #26

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hungarian/stem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down