Repository navigation
Update usearch to include the arena capacity limitation fix - #118828
Conversation
Bumps `contrib/usearch` from `1ae009a` to `6bd13d4`, the tip of the `ClickHouse/v2.24.0` branch of the ClickHouse fork, which includes ClickHouse/usearch#13. That pull request fixes `memory_mapping_allocator_gt::allocate` under-allocating an arena: when a single allocation exceeded the additive allocation threshold, or when `ceil2` overflowed, the new arena could be smaller than the requested block, so the returned pointer extended past the mapping and the caller wrote into unmapped memory. The arena is now grown to at least `head_size() + extended_bytes`, and requests too large to round up without overflowing are rejected up front. The range also picks up the external accessor API (`allocate_vectors_lookup` and `set_vector_at_position`) and relaxes the size/vector-count check on the legacy load path when `exclude_vectors` is set. Both are additive and unused by ClickHouse for now. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [04f93ad] Summary: ✅
AI ReviewSummaryThis PR bumps Findings❌ Blockers
Final Verdict❌ Changes required. The allocator fix is incomplete and still leaves a reproducible overflow path for repeated oversized allocations. LLVM Coverage ReportMeasured on commit 04f93ad.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +261 lines in 61 files (-238 lines lost coverage) · Details |
| @@ -1 +1 @@ | |||
| Subproject commit 1ae009a6aa573629c8871ddb97dd6e1a9c03dd5f | |||
| Subproject commit 6bd13d4c69a1baef1f668e652c3ca26028970f12 | |||
There was a problem hiding this comment.
include/usearch/index_plugins.hpp:989-1020 still has a wrapping-space check. The new max_count_bytes guard only proves that head_size() + extended_bytes fits if we go down the "allocate a new arena" path, but before that we still evaluate last_usage_ + extended_bytes >= last_capacity_. Once an arena already exists, a near-max_count_bytes request can make that addition wrap, the condition becomes false, and we return a pointer inside the current mapping even though the block does not fit.
On a 64-bit build with alignment_ak = 8, count_bytes = SIZE_MAX - 4120 gives extended_bytes = 18446744073709547496. After one such allocation, the next allocation wraps last_usage_ + extended_bytes down to 18446744073709543392, which is smaller than last_capacity_, so the allocator skips the reallocation branch and the caller can still write past the mapping. Please compute the needed space without a wrapping add, for example by checking extended_bytes > last_capacity_ - last_usage_ (after maintaining last_usage_ <= last_capacity_) or by using an explicit overflow check.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units9 translation units recompiled, 54 s compile time in total, 9 of them have a recent master baseline. |
Backport #118828 to 26.7: Update usearch to include the arena capacity limitation fix
Backport #118828 to 26.6: Update usearch to include the arena capacity limitation fix
Backport #118828 to 26.3: Update usearch to include the arena capacity limitation fix
Backport #118828 to 26.8: Update usearch to include the arena capacity limitation fix
…na capacity limitation fix
…na capacity limitation fix
…nt reads Bump contrib/mariadb-connector-c to pick up a single connector change: ERR_clear_error() before every SSL_connect/SSL_read/SSL_write whose result is interpreted through SSL_get_error(), plus capturing errno as the first statement of ma_tls_set_error(). SSL_get_error() only reports the retry flags of the operation just attempted while the calling thread's OpenSSL error queue is empty, and openssl.c never cleared it. A leftover ERR_LIB_SYS entry from any earlier OpenSSL operation on the same thread is therefore reported first (ossl_ssl_get_error() returns SSL_ERROR_SYSCALL for ERR_LIB_SYS before it looks at SSL_want_read() and the BIO retry flag), so a read that OpenSSL had already marked retryable becomes fatal. ma_tls_set_error() then pops the stale entry, gets NULL from ERR_reason_error_string() and prints strerror_r(errno) instead, producing mysqlxx::BadQuery: TLS/SSL error: Interrupted system call (4) on a healthy connection, with an errno that need not belong to the failing call. Every mysql() table function, MySQL table/database engine and MySQL dictionary read is affected: mysqlxx::Connection::connect enables TLS unconditionally via mysql_ssl_set, the sampling query profiler is on by default so query threads take periodic signals, and the TLS path bypasses ma_recv()'s EINTR retry loop because OPENSSL_USE_BIOMETHOD is undefined and SSL_set_fd() lets OpenSSL read the socket directly. No regression test ships with this. With an empty error queue the message is unreachable on the old pin: sock_read() zeroes errno before every recv, EINTR is classified retryable, and pvio_socket_wait_io_or_timeout() re-polls it against its deadline and reports ETIMEDOUT. 428000 instrumented un-injected reads produced none, and no SQL-reachable producer of a stale ERR_LIB_SYS entry was found, so the failing arm of a functional test would be unobservable. The fix was validated by forcing a stale entry on the reading thread instead: 20 of 20 reads and 2-3 of 20 02479_mysql_connect_to_self runs failed before it, 20 of 20 and 50 of 50 passed after, and 125319 stale entries were still measured at SSL entry on the green arm, so that arm is not vacuous. The changelog category is the one the fix-carrying contrib bumps use (usearch ClickHouse#118828, openssl ClickHouse#118927) rather than Bug Fix: the change in this repository is only the dependency pin, and the Bug Fix category's validation expects a regression test that reddens on master, which this defect cannot supply. Related: ClickHouse#105987
…nt reads Bump contrib/mariadb-connector-c to pick up a single connector change: ERR_clear_error() before every SSL_connect/SSL_read/SSL_write whose result is interpreted through SSL_get_error(), plus capturing errno as the first statement of ma_tls_set_error(). SSL_get_error() only reports the retry flags of the operation just attempted while the calling thread's OpenSSL error queue is empty, and openssl.c never cleared it. A leftover ERR_LIB_SYS entry from any earlier OpenSSL operation on the same thread is therefore reported first (ossl_ssl_get_error() returns SSL_ERROR_SYSCALL for ERR_LIB_SYS before it looks at SSL_want_read() and the BIO retry flag), so a read that OpenSSL had already marked retryable becomes fatal. ma_tls_set_error() then pops the stale entry, gets NULL from ERR_reason_error_string() and prints strerror_r(errno) instead, producing mysqlxx::BadQuery: TLS/SSL error: Interrupted system call (4) on a healthy connection, with an errno that need not belong to the failing call. Every mysql() table function, MySQL table/database engine and MySQL dictionary read is affected: mysqlxx::Connection::connect enables TLS unconditionally via mysql_ssl_set, the sampling query profiler is on by default so query threads take periodic signals, and the TLS path bypasses ma_recv()'s EINTR retry loop because OPENSSL_USE_BIOMETHOD is undefined and SSL_set_fd() lets OpenSSL read the socket directly. No regression test ships with this. With an empty error queue the message is unreachable on the old pin: sock_read() zeroes errno before every recv, EINTR is classified retryable, and pvio_socket_wait_io_or_timeout() re-polls it against its deadline and reports ETIMEDOUT. 428000 instrumented un-injected reads produced none, and no SQL-reachable producer of a stale ERR_LIB_SYS entry was found, so the failing arm of a functional test would be unobservable. The fix was validated by forcing a stale entry on the reading thread instead: 20 of 20 reads and 2-3 of 20 02479_mysql_connect_to_self runs failed before it, 20 of 20 and 50 of 50 passed after, and 125319 stale entries were still measured at SSL entry on the green arm, so that arm is not vacuous. The changelog category is the one the fix-carrying contrib bumps use (usearch ClickHouse#118828, openssl ClickHouse#118927) rather than Bug Fix: the change in this repository is only the dependency pin, and the Bug Fix category's validation expects a regression test that reddens on master, which this defect cannot supply. Connector change: ClickHouse/mariadb-connector-c#25 Related: ClickHouse#105987
Changelog category (leave one):
Workflow [PR]
Sync PR [sync-upstream/pr/118828]
Version info
26.9.1.1012(included in26.9and later)26.8.3.80,26.7.7.64,26.6.5.90,26.3.33.33