Skip to content

Commit edab5d2

Browse files
Michael Norrisfacebook-github-bot
authored andcommitted
Add error for overflowing nbits during PQ construction (#3833)
Summary: Pull Request resolved: #3833 size_t expands to unsigned long int, so any left shift more than 31 means ksub overflows. So, we can add a check right before it is constructed in ProductQuantizer. Ramil talked to Matthijs and got to understand that over 16 bits isn't really practical, but we can do 24 to be safe. Reviewed By: mengdilin Differential Revision: D62153881
1 parent d296b2c commit edab5d2

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

faiss/impl/ProductQuantizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void ProductQuantizer::set_derived_values() {
6161
"The dimension of the vector (d) should be a multiple of the number of subquantizers (M)");
6262
dsub = d / M;
6363
code_size = (nbits * M + 7) / 8;
64+
FAISS_THROW_IF_MSG(nbits > 24, "nbits larger than 24 is not practical.");
6465
ksub = 1 << nbits;
6566
centroids.resize(d * ksub);
6667
verbose = false;

0 commit comments

Comments
 (0)