The vulnerability is an integer overflow in the imageproc crate that leads to an out-of-bounds memory read. The root cause is a lack of input validation combined with unsafe arithmetic in the BRIEF feature descriptor implementation.
- The public API
imageproc::binary_descriptors::brief accepts user-provided TestPair coordinates. It passes this data to the internal function brief_impl.
brief_impl did not validate that the coordinates in the TestPairs were within the expected bounds of an image patch. It would calculate new coordinates by adding an offset to the user-provided values.
- These potentially very large, malicious coordinates were then passed to
imageproc::binary_descriptors::local_pixel_average.
- Inside
local_pixel_average, the code calculated a bounding box to sample pixels. The calculation for the maximum coordinates (x_max, y_max) used simple addition (x + radius + 1). When provided with a large coordinate near u32::MAX, this addition would overflow in release builds, wrapping around to a small value.
- This created an invalid bounding box where
x_max could be smaller than x_min. The subsequent check for an empty area was bypassed, and an unsafe_get_pixel call was made with the very large x_min value, resulting in a read past the allocated image buffer.
The patch addresses this by adding validation in brief_impl to reject out-of-range TestPair coordinates and by using saturating_add in local_pixel_average to prevent the integer overflow. During exploitation, a profiler would show a call to brief, which then calls brief_impl and local_pixel_average, where the memory error occurs.