Files
Andrey Vasnetsov 273bbe1729 Fix use-after-free in u8-quantized vector reads on owning storages (#9801)
* Fix use-after-free in u8-quantized vector reads on owning storages

EncodedVectorsU8::get_vec_ptr extracted a raw pointer from the buffer
returned by EncodedStorage::get_vector_data and dropped the buffer
before the pointer was dereferenced. For storages returning
Cow::Borrowed (mmap) this happened to be sound, but for storages that
return Cow::Owned (disk-cache misses, uring backends) every user of
get_vec_ptr read freed memory: the internal SIMD scorers,
encode_internal_vector, and get_quantized_vector_offset_and_code, which
exported the dangling buffer through a safe &[u8].

Make parse_vec_data return the code as a slice borrowing the input, so
the borrow checker forces callers to keep the storage buffer alive
while reading it, and drop get_vec_ptr entirely. This matches how
encoded_vectors_binary already binds the buffers at its scoring sites.
Change get_quantized_vector_offset_and_code to return the code as a
sub-view of the buffer Cow itself, and adapt its GPU caller.

The new regression test drives these paths through a storage that
always returns owned buffers; under Miri it reproduces the
use-after-free on the previous code and passes with this fix.

Fixes #9799

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* additional assertion

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Ivan Pleshkov <pleshkov.ivan@gmail.com>
2026-07-13 16:40:25 +02:00

27 lines
449 B
Rust

#[cfg(test)]
pub mod empty_storage;
#[cfg(test)]
pub mod load_validation;
#[cfg(test)]
pub mod metrics;
#[cfg(test)]
pub mod stop_condition;
#[cfg(test)]
pub mod test_avx2;
#[cfg(test)]
pub mod test_binary;
#[cfg(test)]
pub mod test_binary_encodings;
#[cfg(test)]
pub mod test_neon;
#[cfg(test)]
pub mod test_owned_storage;
#[cfg(test)]
pub mod test_pq;
#[cfg(test)]
pub mod test_simple;
#[cfg(test)]
pub mod test_sse;
#[cfg(test)]
pub mod test_tq;