diff -Nrbu gtk-gnutella-0.97.1/src/core/matching.c gtk-gnutella-0.97.1-OK/src/core/matching.c --- gtk-gnutella-0.97.1/src/core/matching.c 2011-09-11 18:28:24.000000000 +0400 +++ gtk-gnutella-0.97.1-OK/src/core/matching.c 2011-12-02 16:32:30.000000000 +0400 @@ -700,6 +700,9 @@ sf = e->sf; + if (!shared_file_is_shareable(sf)) + continue; /* Cannot be shared */ + canonic_len = shared_file_name_canonic_len(sf); if (canonic_len < minlen) continue; /* Can't match */ diff -Nrbu gtk-gnutella-0.97.1/src/core/share.c gtk-gnutella-0.97.1-OK/src/core/share.c --- gtk-gnutella-0.97.1/src/core/share.c 2011-09-11 18:28:26.000000000 +0400 +++ gtk-gnutella-0.97.1-OK/src/core/share.c 2011-12-02 16:36:47.000000000 +0400 @@ -2460,6 +2460,25 @@ return NULL != sf->fi; } +gboolean +shared_file_is_shareable(const shared_file_t *sf) +{ + shared_file_check(sf); + + /* + * A zeroed file_index indicates we called shared_file_deindex(), + * most probably through shared_file_remove(). + * + * We don't want to include this file in query hits even though the + * file entry happens to be still listed in search bins (for instance + * because it was removed dynamically as we discovered it was spam). + * + * Thanks to Dmitry Butskoy for investigating this corner case. + */ + + return sf->file_index != 0; +} + filesize_t shared_file_size(const shared_file_t *sf) { diff -Nrbu gtk-gnutella-0.97.1/src/core/share.h gtk-gnutella-0.97.1-OK/src/core/share.h --- gtk-gnutella-0.97.1/src/core/share.h 2011-09-11 18:28:26.000000000 +0400 +++ gtk-gnutella-0.97.1-OK/src/core/share.h 2011-12-02 16:37:42.000000000 +0400 @@ -112,6 +112,7 @@ gboolean sha1_hash_is_uptodate(shared_file_t *sf); gboolean shared_file_is_partial(const shared_file_t *sf); gboolean shared_file_is_finished(const shared_file_t *sf); +gboolean shared_file_is_shareable(const shared_file_t *sf); filesize_t shared_file_size(const shared_file_t *sf); guint32 shared_file_index(const shared_file_t *sf); time_t shared_file_modification_time(const shared_file_t *sf);