Repository navigation
Validate rabbitmq_routing_key_list in the RabbitMQ engine - #125661
Conversation
For the `headers` exchange type, `StorageRabbitMQ::bindExchange` and `RabbitMQProducer` split each routing key on `=` and read the second part unconditionally, so a key without `=` caused an out-of-bounds read (a libc++ hardening assertion and process termination). An explicitly empty `rabbitmq_routing_key_list` caused the same kind of out-of-bounds read of `routing_keys[0]` for binding and publishing. Reject both at table creation with `BAD_ARGUMENTS`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [3d71ad8] Summary: ✅
AI ReviewSummaryThe PR prevents out-of-bounds routing-key accesses in Findings❌ Blockers
Missing context / blind spots
Tests
Final Verdict❌ Block. Preserve valid |
| [](const String & name) { return name.starts_with(deadletter_exchange_setting); }); | ||
|
|
||
| /// The first routing key is used unconditionally for binding and publishing. | ||
| if (routing_keys.empty()) |
There was a problem hiding this comment.
rabbitmq_routing_key_list is not universally required. With rabbitmq_queue_consume = 1, StorageRabbitMQ::initRabbitMQ skips bindExchange on the read path and consumes directly from queue_base; for fanout, RabbitMQ ignores the routing key anyway. This unconditional check turns those configurations into BAD_ARGUMENTS even though the only invariant we need here is “do not dereference routing_keys[0] when the list is empty”.
Could we normalize the empty case to "" (or gate the check to modes that actually use a routing key) instead of rejecting every empty value up front?
There was a problem hiding this comment.
🕵 Agreed. An empty rabbitmq_routing_key_list is now normalized to a single empty routing key, so it is accepted again and routing_keys[0] is still always valid. The empty-list test case was removed because table creation now goes on to connect to the broker. Fixed in 3d71ad8 (commit "Address review: treat empty rabbitmq_routing_key_list as one empty key").
There was a problem hiding this comment.
The claimed empty-list fix is still incomplete for rabbitmq_exchange_type = 'headers', rabbitmq_queue_consume = 1, rabbitmq_routing_key_list = ''. At StorageRabbitMQ.cpp:158–168, normalization creates routing_keys = {""}, then the header validation throws BAD_ARGUMENTS because that synthetic entry has no =. This configuration previously consumed rabbitmq_queue_base without binding an exchange (StorageRabbitMQ::initRabbitMQ, lines 514–517). The new check also runs during ATTACH, so existing tables using it fail to load after upgrading.
Preserve empty header sets for direct queue consumption, enforce header validation at the binding/producer parsing boundaries, and cover creation plus reattachment in the existing RabbitMQ integration suite.
There was a problem hiding this comment.
It is a different problem. The goal of this PR is to fix an out-of-bounds read.
An empty routing key list is a valid configuration (e.g. `fanout` ignores the routing key and `rabbitmq_queue_consume = 1` does not bind at all), so instead of rejecting it, normalize it to a single empty routing key. This still avoids the out-of-bounds read of `routing_keys[0]`. Also fix the `readability-container-contains` clang-tidy error reported in https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125661&sha=d708b14288566a3fdde0a8120dd32c7eee1fd1ea&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29 PR: #125661 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #125661 to 26.9: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
Backport #125661 to 26.8: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
Backport #125661 to 26.7: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
Backport #125661 to 26.3: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
…st` in the `RabbitMQ` engine
For the
headersexchange type,StorageRabbitMQ::bindExchangeandRabbitMQProducersplit each routing key on=and read the second part unconditionally. A key without=(e.g.rabbitmq_routing_key_list = 'format,logs') caused an out-of-bounds read, terminating the server process on a libc++ hardening assertion.Such keys are now rejected at table creation with
BAD_ARGUMENTS, before connecting to the broker. Keys whose value contains=are still accepted as before.An explicitly empty
rabbitmq_routing_key_listcaused the same kind of out-of-bounds read ofrouting_keys[0]when binding and publishing. An empty list is a valid configuration (e.g.fanout, orrabbitmq_queue_consume = 1), so it is now treated as a single empty routing key.The problem was found and reported by @dstesk (https://github.com/dstesk).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash when a
RabbitMQtable with theheadersexchange type had a routing key without=, or whenrabbitmq_routing_key_listwas empty. Routing keys without=for theheadersexchange type are now rejected with an exception. The problem was found and reported by @dstesk (https://github.com/dstesk).🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/125661]
Version info
26.10.1.2404-master(included in26.10and later)26.9.20.9,26.8.28.9,26.7.31.10,26.3.52.7