Skip to content

Commit

Permalink
packedArray check if wordId belongs to valid boundaries of values
Browse files Browse the repository at this point in the history
  • Loading branch information
alldroll committed Jul 26, 2020
1 parent 6200ec3 commit ffde11a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/lm/packed_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ func (s *packedArray) find(wordID WordID, context ContextOffset) (packedValue, C
values = s.values[from:to]
}

if getWordID(values[0]) > wordID || getWordID(values[len(values)-1]) < wordID {
return 0, InvalidContextOffset
}

target := newPackedValue(wordID, 0)
j := sort.Search(len(values), func(i int) bool { return values[i] >= target })

Expand Down

0 comments on commit ffde11a

Please sign in to comment.