Commit f1efc2c
Validate codes/ntotal consistency in Ix2L and IxLa deserialization (#5439)
Summary:
Pull Request resolved: #5439
Two faiss deserialization branches accept an index whose `ntotal` is
inconsistent with its stored `codes`, so the first `reconstruct()` reads
through a null (or out-of-bounds) `codes.data()`:
- `Ix2L` (Index2Layer): reads `ntotal` (header), `code_size_1`,
`code_size_2`, `code_size`, and `codes` independently. Unlike every
sibling `IndexFlatCodes` reader it never checked
`codes.size() == ntotal * code_size`. It also never checked that the
coarse-code width `code_size_1` matches `q1.nlist` -- and because a PQ
with `nbits == 0` yields `code_size_2 == 0`, a forged
`code_size_1 == code_size == 0` made the size check vacuous
(`0 == ntotal * 0`) while `Level1Quantizer::decode_listno` still reads
`coarse_code_size(nlist)` bytes from an empty `codes` buffer
(near-null read at IndexIVF.cpp:148).
- `IxLa` (IndexLattice): the writer persists the header (including
`ntotal`) but never writes the `codes` vector, so a well-formed IxLa
index is always empty. A forged `ntotal > 0` leaves `codes` empty and
`IndexLattice::sa_decode` hands `codes.data() == nullptr` to
`BitstringReader::read`.
Adds to Ix2L both the standard `mul_no_overflow` codes-size check and a
`code_size_1 == q1.coarse_code_size()` check (so the coarse width matches
nlist and the size check can no longer be made vacuous). For IxLa enforces
`ntotal == 0` plus header/encoded `d` consistency. All convert a SIGSEGV
into a clean FaissException, matching the existing hardening on this
surface. Found by agentic fuzzing.
Reviewed By: trang-nm-nguyen
Differential Revision: D112368337
fbshipit-source-id: 883256965daff9302c505d80e0ac42cf730747ef1 parent a238933 commit f1efc2c
1 file changed
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2143 | 2143 | | |
2144 | 2144 | | |
2145 | 2145 | | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
2146 | 2156 | | |
2147 | 2157 | | |
2148 | 2158 | | |
| |||
2378 | 2388 | | |
2379 | 2389 | | |
2380 | 2390 | | |
| 2391 | + | |
| 2392 | + | |
| 2393 | + | |
| 2394 | + | |
2381 | 2395 | | |
2382 | 2396 | | |
2383 | 2397 | | |
| |||
2387 | 2401 | | |
2388 | 2402 | | |
2389 | 2403 | | |
| 2404 | + | |
| 2405 | + | |
| 2406 | + | |
| 2407 | + | |
| 2408 | + | |
| 2409 | + | |
2390 | 2410 | | |
2391 | 2411 | | |
2392 | 2412 | | |
| |||
0 commit comments