From 7e3f6875c166ffe92fc214c17bd8100d59b29a0e Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Fri, 24 May 2024 23:45:53 +0200 Subject: [PATCH] Prevent signed integer overflow in LshTable This change keeps everything as size_t and the expression is valid because maxk_block > 0 in hte loop. --- modules/flann/include/opencv2/flann/lsh_table.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/flann/include/opencv2/flann/lsh_table.h b/modules/flann/include/opencv2/flann/lsh_table.h index 3b8ffd4075..3f51457cbb 100644 --- a/modules/flann/include/opencv2/flann/lsh_table.h +++ b/modules/flann/include/opencv2/flann/lsh_table.h @@ -424,7 +424,7 @@ inline size_t LshTable::getKey(const unsigned char* feature) cons size_t mask_block = mask_[i / sizeof(size_t)]; while (mask_block) { // Get the lowest set bit in the mask block - size_t lowest_bit = mask_block & (-(ptrdiff_t)mask_block); + size_t lowest_bit = mask_block & ~(mask_block - 1); // Add it to the current subsignature if necessary subsignature += (feature_block & lowest_bit) ? bit_index : 0; // Reset the bit in the mask block