Skip to content

Commit a9ecee2

Browse files
Juan Carpio Castellanosmeta-codesync[bot]
authored andcommitted
Reject AdditiveQuantizer with zero-bit code size on deserialization (#5506)
Summary: Pull Request resolved: #5506 Deserializing an AdditiveQuantizer-based index (residual quantizer, local-search quantizer, and their product variants) validated that the number of sub-quantizers M is positive, but not that the resulting per-vector code size is nonzero. A crafted index can set every sub-quantizer's bit width to 0, which makes the derived code size 0 while the index still declares a positive vector count. Such an index ends up with an empty codes buffer whose data pointer is null/unspecified. Decoding any vector then dereferences that pointer inside the bitstring reader used to unpack per-vector codes, causing a segfault on fully attacker-controlled input. Reject this configuration right where the code size is derived, with a descriptive exception. A quantizer that stores zero bits per vector cannot decode anything and is never produced by real training, so this only rejects malformed/crafted inputs. Reviewed By: trang-nm-nguyen Differential Revision: D115173394 fbshipit-source-id: 289c16f1da7280af04a2be6a5629d5af6154a3e7
1 parent 4de3bbb commit a9ecee2

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

faiss/impl/index_read.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ static void read_AdditiveQuantizer(AdditiveQuantizer& aq, IOReader* f) {
821821
}
822822

823823
aq.set_derived_values();
824+
FAISS_THROW_IF_NOT_FMT(
825+
aq.code_size > 0,
826+
"invalid AdditiveQuantizer: nbits sum to 0 bits, code_size %zd",
827+
aq.code_size);
824828

825829
// Sanity-check codebooks size without knowing the effective dimension.
826830
// codebooks stores effective_d * total_codebook_size floats, so its

0 commit comments

Comments
 (0)