Skip to content

Commit

Permalink
search.Beam: Fix invalid indexing (#633)
Browse files Browse the repository at this point in the history
If none of the states of the beam have valid moves, it was attempted to
index into the vector of scored valid moves anyway, which results in
invalid memory access.

Fix this by first checking that there valid moves before attempting to
index into them.
  • Loading branch information
danieldk authored Apr 26, 2022
1 parent 73a2987 commit 6c3bd1b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions thinc/extra/search.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,14 @@ cdef class Beam:
entry.first = s.score + scores[i][j]
entry.second = move_id + j
entries.push_back(entry)
cdef double max_ = entries[0].first
cdef double Z = 0.
cdef double cutoff = 0.0
cdef double max_, Z, cutoff
if self.min_density == 0.0:
for i in range(entries.size()):
q.push(entries[i])
else:
elif not entries.empty():
max_ = entries[0].first
Z = 0.
cutoff = 0.
# Softmax into probabilities, so we can prune
for i in range(entries.size()):
if entries[i].first > max_:
Expand Down

0 comments on commit 6c3bd1b

Please sign in to comment.