Repository navigation
Patch confluent-kafka to stop reading commit metadata past its end - #25702
alexeypilyugin wants to merge 2 commits into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Warning This PR changes Agent dependencies. Do not merge it until the wheels are promoted. Dependency inputs changed, so the dependency resolution and wheel build workflow runs on this branch. It takes 1.5 to 3 hours and finishes by committing updated lockfiles. The wheels it builds then have to be promoted before the Agent can use them. Steps to take, in order:
Merging before promotion leaves the Agent unable to install the wheels these lockfiles pin. Pushing again to this branch invalidates the promotion, so if you push after step 4 you have to promote again. Head commit |
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 5df1b73 | Docs | View more details | Give us feedback! |
evalya-impact-summaryevalya impact analysis |
Validation Report
Run Passed validations (20)
|
Disk usage changeCommit Uncompressed
Details
Compressed
Details
|
|
Closing in favor of #25483 |
What does this PR do?
Builds the
confluent-kafkawheel from a patched copy of the 2.13.2 sdist, on all builder platforms (Linux x86_64/aarch64, macOS, Windows).The patch (
.builders/patches/confluent-kafka-fix-metadata-overread.patch) changesTopicPartition_setupinsrc/confluent_kafka/src/confluent_kafka.cto copy commit metadata usingmetadata_sizeinstead ofstrdup().Motivation
librdkafka returns commit metadata as a buffer plus
metadata_size, with no NUL terminator promised (rdkafka.h), andrd_kafka_topic_partition_updatecopies exactlymetadata_sizebytes.c_part_to_pythen callsstrdup()on that buffer, which reads until it finds a zero byte somewhere past the end.Metadata committed by non-confluent-kafka-python clients (Java, kafka-python, ...) has no trailing NUL, so
list_consumer_group_offsetsin thekafka_consumercheck over-reads. When the buffer fills a jemalloc size class exactly, the read can run into an unmapped page and segfault the Agent.Reproduced under AddressSanitizer with a librdkafka mock cluster: the unpatched build reports a heap-buffer-overflow in
strdup<-c_part_to_py<-Admin_c_GroupResults_to_py; the patched build is clean and returns the same values.The build steps download the sdist from PyPI with a pinned SHA-256 and point the
confluent-kafkarequirement at the patched directory. Theconfluent-kafka==pin inconstraints.txtstill applies. The hash check fails loudly if the version is bumped, so the patch gets reviewed again.Why not fix it in librdkafka instead?
librdkafka defines
metadataas a byte buffer plusmetadata_size(rdkafka.h), so not adding a NUL is allowed by its API. Makingrd_kafka_topic_partition_updateadd one would fix only that copy. Other places also copy exactlymetadata_sizebytes:rd_kafka_topic_partition_set_metadata_from_rktp_stored, with metadata stored byrd_kafka_offset_store0rd_kafka_topic_partition_list_updateAny future copy could drop the NUL again. Reading with
metadata_sizein the binding fixes all of them in one place.This should be reported and fixed upstream in confluent-kafka-python; this patch can be dropped once a fixed release is used.
Review checklist
kafka_consumerCI environment still installs confluent-kafka from PyPI, so it does not run the patched code.