File tree 1 file changed +5
-4
lines changed
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -1835,21 +1835,22 @@ namespace hnswlib
1835
1835
std::unordered_set<tableint> s;
1836
1836
for (int j = 0 ; j < size; j++)
1837
1837
{
1838
- assert (data[j] > 0 );
1839
- assert (data[j] < cur_element_count);
1840
- assert (data[j] != i);
1838
+ if (data[j] < 0 || data[j] >= cur_element_count || data[j] == i)
1839
+ throw std::runtime_error (" HNSW Integrity failure: invalid neighbor index" );
1841
1840
inbound_connections_num[data[j]]++;
1842
1841
s.insert (data[j]);
1843
1842
connections_checked++;
1844
1843
}
1845
- assert (s.size () == size);
1844
+ if (s.size () != size)
1845
+ throw std::runtime_error (" HNSW Integrity failure: duplicate neighbor index" );
1846
1846
}
1847
1847
}
1848
1848
if (cur_element_count > 1 )
1849
1849
{
1850
1850
int min1 = inbound_connections_num[0 ], max1 = inbound_connections_num[0 ];
1851
1851
for (int i = 0 ; i < cur_element_count; i++)
1852
1852
{
1853
+ // This should always be true regardless the data is corrupted or not
1853
1854
assert (inbound_connections_num[i] > 0 );
1854
1855
min1 = std::min (inbound_connections_num[i], min1);
1855
1856
max1 = std::max (inbound_connections_num[i], max1);
You can’t perform that action at this time.
0 commit comments