Skip to content

Patch confluent-kafka to stop reading commit metadata past its end - #25702

Closed
alexeypilyugin wants to merge 2 commits into
masterfrom
alexeypilyugin/confluent-kafka-metadata-overread
Closed

alexeypilyugin wants to merge 2 commits into
masterfrom
alexeypilyugin/confluent-kafka-metadata-overread

Conversation

@alexeypilyugin

@alexeypilyugin alexeypilyugin commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Builds the confluent-kafka wheel 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) changes TopicPartition_setup in src/confluent_kafka/src/confluent_kafka.c to copy commit metadata using metadata_size instead of strdup().

Motivation

librdkafka returns commit metadata as a buffer plus metadata_size, with no NUL terminator promised (rdkafka.h), and rd_kafka_topic_partition_update copies exactly metadata_size bytes. c_part_to_py then calls strdup() 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_offsets in the kafka_consumer check 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-kafka requirement at the patched directory. The confluent-kafka== pin in constraints.txt still 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 metadata as a byte buffer plus metadata_size (rdkafka.h), so not adding a NUL is allowed by its API. Making rd_kafka_topic_partition_update add one would fix only that copy. Other places also copy exactly metadata_size bytes:

Any future copy could drop the NUL again. Reading with metadata_size in 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

  • Linux, macOS and Windows wheel builds pass.
  • The kafka_consumer CI environment still installs confluent-kafka from PyPI, so it does not run the patched code.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. Wait for the resolution workflow to finish and commit the lockfiles to this branch.
  2. Review the Agent build triggered by that commit (default-pipeline in GitLab), especially static_quality_gate.
  3. Get the PR approved.
  4. Ask an agent-integrations maintainer to promote the wheels. Promotion dispatches a workflow that requires write access to this repository, so only a maintainer can run it (an outside contributor cannot):
    ddev dep promote https://github.com/DataDog/integrations-core/pull/25702
    
  5. Wait for dependency-wheel-promotion to turn green. Only then merge.

Merging before promotion leaves the Agent unable to install the wheels these lockfiles pin. dependency-wheel-promotion is a required check: if it is pending or red, that is intentional. Do not bypass it and do not ask for an admin merge.

Pushing again to this branch invalidates the promotion, so if you push after step 4 you have to promote again.

Head commit 5df1b737665afe2a1777db31b1699185a184b212. Full process: Dependency Updates. This comment is updated automatically as promotion progresses.

@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Pipelines

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 1 Pipeline job failed

Validate repository | Run Validations / Validate

View more details · View in GitHub Actions

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 5df1b73 | Docs | View more details | Give us feedback!

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

evalya-impact-summary

evalya impact analysis
Impact analysis: 0 selected, 0 skipped (of 0 test tasks)
Publish tasks:   2 (always emitted)
Diff (5 files):
  .builders/images/linux-aarch64/build_script.sh
  .builders/images/linux-x86_64/build_script.sh
  .builders/images/macos/extra_build.sh
  .builders/images/windows-x86_64/build_script.ps1
  .builders/patches/confluent-kafka-fix-metadata-overread.patch

Debug a specific task: evalya plan impact --path <path> --task <task>

Learn more about CI impact filtering

@dd-octo-sts

dd-octo-sts Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Validation Report

Validation Description Status
pr-description Validate the pull request checklist and visible description length

To fix: Tick every item in .github/PULL_REQUEST_TEMPLATE.md and keep the description under 3,000 visible characters.
❌
qa-label Validate the pull request declares whether it needs QA for the next Agent release

To fix: Choose exactly one QA label:
• qa/required if the PR needs QA validation.
• qa/skip-qa if the PR does not need QA validation.
❌

Run ddev validate all changed --fix to attempt to auto-fix supported validations.

Passed validations (20)
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file ✅
ci Validate CI configuration and code coverage settings ✅
codeowners Validate every integration has a CODEOWNERS entry ✅
config Validate default configuration files against spec.yaml ✅
dep Verify dependency pins are consistent and Agent-compatible ✅
http Validate integrations use the HTTP wrapper correctly ✅
imports Validate check imports do not use deprecated modules ✅
integration-style Validate check code style conventions ✅
jmx-metrics Validate JMX metrics definition files and config ✅
labeler Validate PR labeler config matches integration directories ✅
legacy-signature Validate no integration uses the legacy Agent check signature ✅
license-headers Validate Python files have proper license headers ✅
licenses Validate third-party license attribution list ✅
metadata Validate metadata.csv metric definitions ✅
models Validate configuration data models match spec.yaml ✅
openmetrics Validate OpenMetrics integrations disable the metric limit ✅
package Validate Python package metadata and naming ✅
readmes Validate README files have required sections ✅
saved-views Validate saved view JSON file structure and fields ✅
version Validate version consistency between package and changelog ✅

View full run

@dd-octo-sts

dd-octo-sts Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Disk usage change

Commit 5df1b73 compared against 694aae7.

Uncompressed

linux-aarch64 linux-x86_64 macos-aarch64 macos-x86_64 windows-x86_64
🔺 +224.13 KiB 🔺 +224.13 KiB 🔺 +224.13 KiB 🔺 +224.13 KiB 🔺 +224.13 KiB
Details
Name Version Type linux-aarch64 linux-x86_64 macos-aarch64 macos-x86_64 windows-x86_64
setuptools 84.0.0 -> 84.2.0 Dependency 🔺 +222.18 KiB 🔺 +222.18 KiB 🔺 +222.18 KiB 🔺 +222.18 KiB 🔺 +222.18 KiB
jsonpointer 3.2.1 -> 3.4 Dependency 🔺 +2.81 KiB 🔺 +2.81 KiB 🔺 +2.81 KiB 🔺 +2.81 KiB 🔺 +2.81 KiB
certifi 2026.7.22 -> 2026.10.19 Dependency 🟢 -1.27 KiB 🟢 -1.27 KiB 🟢 -1.27 KiB 🟢 -1.27 KiB 🟢 -1.27 KiB
jsonpatch 1.35 -> 1.36 Dependency 🔺 +369 B 🔺 +369 B 🔺 +369 B 🔺 +369 B 🔺 +369 B
s3transfer 0.19.2 -> 0.19.3 Dependency 🔺 +51 B 🔺 +51 B 🔺 +51 B 🔺 +51 B 🔺 +51 B

Compressed

linux-aarch64 linux-x86_64 macos-aarch64 macos-x86_64 windows-x86_64
🔺 +55.46 KiB 🔺 +55.91 KiB 🔺 +55.87 KiB 🔺 +55.86 KiB 🔺 +55.89 KiB
Details
Name Version Type linux-aarch64 linux-x86_64 macos-aarch64 macos-x86_64 windows-x86_64
setuptools 84.0.0 -> 84.2.0 Dependency 🔺 +55.47 KiB 🔺 +55.47 KiB 🔺 +55.47 KiB 🔺 +55.47 KiB 🔺 +55.47 KiB
jsonpointer 3.2.1 -> 3.4 Dependency 🔺 +743 B 🔺 +743 B 🔺 +743 B 🔺 +743 B 🔺 +743 B
certifi 2026.7.22 -> 2026.10.19 Dependency 🟢 -529 B 🟢 -529 B 🟢 -529 B 🟢 -529 B 🟢 -529 B
jsonpatch 1.35 -> 1.36 Dependency 🔺 +89 B 🔺 +89 B 🔺 +89 B 🔺 +89 B 🔺 +89 B
cryptography 50.0.1 Dependency 🟢 -344 B 🔺 +44 B 0 B 🟢 -9 B 0 B
confluent-kafka 2.13.2 Dependency 🔺 +6 B 🔺 +34 B 🔺 +80 B 🔺 +65 B 🔺 +95 B
s3transfer 0.19.2 -> 0.19.3 Dependency 🔺 +36 B 🔺 +36 B 🔺 +36 B 🔺 +36 B 🔺 +36 B
krb5 0.10.0 Dependency 🟢 -1 B 🔺 +25 B 0 B 0 B 0 B
gssapi 1.12.0 Dependency 🟢 -13 B 🔺 +5 B 0 B 0 B 0 B
platformdirs 4.13.4 -> 4.13.5 Dependency 🟢 -3 B 🟢 -3 B 🟢 -3 B 🟢 -3 B 🟢 -3 B
ddtrace 4.13.2 Dependency 0 B 0 B 🟢 -9 B 🟢 -1 B 0 B
psycopg-c 3.3.4 Dependency 0 B 0 B 0 B 0 B 🟢 -4 B
pymqi 1.12.13 Dependency 0 B 0 B 0 B 0 B 🟢 -1 B

@steveny91

steveny91 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closing in favor of #25483

@steveny91 steveny91 closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants