Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .builders/images/linux-aarch64/build_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@ if [[ "${DD_BUILD_PYTHON_VERSION}" == "3" ]]; then
VERSION="${kafka_version}" \
SHA256="14972092e4115f6e99f798a7cb420cbf6daa0c73502b3c52ae42fb5b418eea8f" \
RELATIVE_PATH="librdkafka-{{version}}" \
PATCHES="librdkafka-fix-coord-request-uaf.patch" \
PATCHES="librdkafka-fix-coord-request-uaf.patch librdkafka-fix-offsetfetch-null-cgrp.patch" \
bash install-from-source.sh --enable-sasl --enable-curl --enable-zstd
# confluent-kafka's C extension reads offset commit metadata with strdup() although it is not
# NUL-terminated. Build the extension from a patched copy of the sdist instead of the PyPI one.
confluent_kafka_src="/tmp/confluent_kafka-${kafka_version}"
curl -L "https://files.pythonhosted.org/packages/source/c/confluent-kafka/confluent_kafka-${kafka_version}.tar.gz" \
-o "${confluent_kafka_src}.tar.gz"
echo "619d10d1d77c9821ba913b3e42a33ade7f889f3573c7f3c17b57c3056e3310f5 ${confluent_kafka_src}.tar.gz" | sha256sum --check
tar -C /tmp -xzf "${confluent_kafka_src}.tar.gz"
patch -d "${confluent_kafka_src}" -p1 -i /home/patches/confluent-kafka-fix-metadata-overread.patch
sed -i "s|^confluent-kafka==.*|confluent-kafka @ file://${confluent_kafka_src}|" /home/requirements.in
always_build+=("confluent-kafka")

# The version of pyodbc is dynamically linked against a version of the odbc which doesn't come included in the wheel
Expand Down
11 changes: 10 additions & 1 deletion .builders/images/linux-x86_64/build_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ if [[ "${DD_BUILD_PYTHON_VERSION}" == "3" ]]; then
VERSION="${kafka_version}" \
SHA256="14972092e4115f6e99f798a7cb420cbf6daa0c73502b3c52ae42fb5b418eea8f" \
RELATIVE_PATH="librdkafka-{{version}}" \
PATCHES="librdkafka-fix-coord-request-uaf.patch" \
PATCHES="librdkafka-fix-coord-request-uaf.patch librdkafka-fix-offsetfetch-null-cgrp.patch" \
bash install-from-source.sh --enable-sasl --enable-curl --enable-zstd
# confluent-kafka's C extension reads offset commit metadata with strdup() although it is not
# NUL-terminated. Build the extension from a patched copy of the sdist instead of the PyPI one.
confluent_kafka_src="/tmp/confluent_kafka-${kafka_version}"
curl -L "https://files.pythonhosted.org/packages/source/c/confluent-kafka/confluent_kafka-${kafka_version}.tar.gz" \
-o "${confluent_kafka_src}.tar.gz"
echo "619d10d1d77c9821ba913b3e42a33ade7f889f3573c7f3c17b57c3056e3310f5 ${confluent_kafka_src}.tar.gz" | sha256sum --check
tar -C /tmp -xzf "${confluent_kafka_src}.tar.gz"
patch -d "${confluent_kafka_src}" -p1 -i /home/patches/confluent-kafka-fix-metadata-overread.patch
sed -i "s|^confluent-kafka==.*|confluent-kafka @ file://${confluent_kafka_src}|" /home/requirements.in
always_build+=("confluent-kafka")

# The version of pyodbc is dynamically linked against a version of the odbc which doesn't come included in the wheel
Expand Down
14 changes: 14 additions & 0 deletions .builders/images/macos/extra_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,26 @@ if [[ "${DD_BUILD_PYTHON_VERSION}" == "3" ]]; then
VERSION="${kafka_version}" \
SHA256="14972092e4115f6e99f798a7cb420cbf6daa0c73502b3c52ae42fb5b418eea8f" \
RELATIVE_PATH="librdkafka-{{version}}" \
PATCHES="librdkafka-fix-coord-request-uaf.patch librdkafka-fix-offsetfetch-null-cgrp.patch" \
bash install-from-source.sh --prefix="${DD_PREFIX_PATH}" --enable-sasl --enable-curl --enable-zstd

# lmdb doesnt't get the actual full path in its install name which means delocate won't find it
# Luckily we can patch it here so that it does.
install_name_tool -change liblmdb.so "${DD_PREFIX_PATH}/lib/liblmdb.so" "${DD_PREFIX_PATH}/lib/librdkafka.1.dylib"
install_name_tool -change /usr/local/lib/libzstd.1.dylib "${DD_PREFIX_PATH}/lib/libzstd.1.dylib" "${DD_PREFIX_PATH}/lib/librdkafka.1.dylib"

# confluent-kafka's C extension reads offset commit metadata with strdup() although it is not
# NUL-terminated. Build the extension from a patched copy of the sdist instead of the PyPI one.
confluent_kafka_src="/tmp/confluent_kafka-${kafka_version}"
curl -L "https://files.pythonhosted.org/packages/source/c/confluent-kafka/confluent_kafka-${kafka_version}.tar.gz" \
-o "${confluent_kafka_src}.tar.gz"
echo "619d10d1d77c9821ba913b3e42a33ade7f889f3573c7f3c17b57c3056e3310f5 ${confluent_kafka_src}.tar.gz" | sha256sum --check
rm -rf "${confluent_kafka_src}"
tar -C /tmp -xzf "${confluent_kafka_src}.tar.gz"
patch -d "${confluent_kafka_src}" -p1 -i "${DD_MOUNT_DIR}/patches/confluent-kafka-fix-metadata-overread.patch"
# -i.bak keeps this working with both BSD and GNU sed
sed -i.bak "s|^confluent-kafka==.*|confluent-kafka @ file://${confluent_kafka_src}|" "${DD_MOUNT_DIR}/requirements.in"
rm "${DD_MOUNT_DIR}/requirements.in.bak"
always_build+=("confluent-kafka")

# ddtrace publishes macosx_14_0 wheels because upstream builds its extensions against the
Expand Down
19 changes: 19 additions & 0 deletions .builders/images/windows-x86_64/build_script.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ git checkout $desired_commit
Write-Host "Bootstrapping vcpkg..."
.\bootstrap-vcpkg.bat

# Apply the same patches as the Linux and macOS builders, which pass them to install-from-source.sh
foreach ($patch in 'librdkafka-fix-coord-request-uaf.patch', 'librdkafka-fix-offsetfetch-null-cgrp.patch') {
git -C $librdkafka_dir apply --verbose "C:\mnt\patches\$patch"
}

# Get deps
Set-Location "$librdkafka_dir"
# Patch the the vcpkg manifest to to override the OpenSSL version and CURL version
Expand Down Expand Up @@ -67,3 +72,17 @@ Copy-Item "${srcdir}\librdkafka.lib","${srcdir}\librdkafkacpp.lib" -Destination
New-Item -Path $includedir\librdkafka -ItemType Directory
Copy-Item -Path ".\src\*" -Filter *.h -Destination $includedir\librdkafka

# confluent-kafka's C extension reads offset commit metadata with strdup() although it is not
# NUL-terminated. Build the extension from a patched copy of the sdist instead of the PyPI one.
$confluent_kafka_src = "C:\confluent_kafka-${kafka_version}"
Get-RemoteFile `
-Uri "https://files.pythonhosted.org/packages/source/c/confluent-kafka/confluent_kafka-${kafka_version}.tar.gz" `
-Path "C:\confluent_kafka-${kafka_version}.tar.gz" `
-Hash '619d10d1d77c9821ba913b3e42a33ade7f889f3573c7f3c17b57c3056e3310f5'
7z x "C:\confluent_kafka-${kafka_version}.tar.gz" -o"C:\"
7z x "C:\confluent_kafka-${kafka_version}.tar" -o"C:\"
Remove-Item "C:\confluent_kafka-${kafka_version}.tar.gz","C:\confluent_kafka-${kafka_version}.tar"
git -C $confluent_kafka_src apply --verbose "C:\mnt\patches\confluent-kafka-fix-metadata-overread.patch"
(Get-Content 'C:\mnt\requirements.in') -replace '^confluent-kafka==.*', "confluent-kafka @ file:///C:/confluent_kafka-${kafka_version}" |
Set-Content 'C:\mnt\requirements.in'

63 changes: 63 additions & 0 deletions .builders/patches/confluent-kafka-fix-metadata-overread.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
diff --git a/src/confluent_kafka/src/confluent_kafka.c b/src/confluent_kafka/src/confluent_kafka.c
index 0a2c584..cb95f3c 100644
--- a/src/confluent_kafka/src/confluent_kafka.c
+++ b/src/confluent_kafka/src/confluent_kafka.c
@@ -1271,6 +1271,7 @@ static void TopicPartition_setup(TopicPartition *self,
long long offset,
int32_t leader_epoch,
const char *metadata,
+ size_t metadata_size,
rd_kafka_resp_err_t err) {
self->topic = strdup(topic);
self->partition = partition;
@@ -1281,7 +1282,11 @@ static void TopicPartition_setup(TopicPartition *self,
self->leader_epoch = leader_epoch;

if (metadata != NULL) {
- self->metadata = strdup(metadata);
+ /* metadata is not guaranteed to be NUL-terminated:
+ * librdkafka passes it as a buffer plus metadata_size. */
+ self->metadata = malloc(metadata_size + 1);
+ memcpy(self->metadata, metadata, metadata_size);
+ self->metadata[metadata_size] = '\0';
} else {
self->metadata = NULL;
}
@@ -1317,7 +1322,8 @@ TopicPartition_init(PyObject *self, PyObject *args, PyObject *kwargs) {
}

TopicPartition_setup((TopicPartition *)self, topic, partition, offset,
- leader_epoch, metadata, 0);
+ leader_epoch, metadata,
+ metadata ? strlen(metadata) : 0, 0);
return 0;
}

@@ -1529,6 +1535,7 @@ static PyObject *TopicPartition_new0(const char *topic,
long long offset,
int32_t leader_epoch,
const char *metadata,
+ size_t metadata_size,
rd_kafka_resp_err_t err) {
TopicPartition *self;

@@ -1536,7 +1543,7 @@ static PyObject *TopicPartition_new0(const char *topic,
NULL, NULL);

TopicPartition_setup(self, topic, partition, offset, leader_epoch,
- metadata, err);
+ metadata, metadata_size, err);

return (PyObject *)self;
}
@@ -1546,8 +1553,8 @@ static PyObject *TopicPartition_new0(const char *topic,
PyObject *c_part_to_py(const rd_kafka_topic_partition_t *rktpar) {
return TopicPartition_new0(
rktpar->topic, rktpar->partition, rktpar->offset,
- rd_kafka_topic_partition_get_leader_epoch(rktpar), rktpar->metadata,
- rktpar->err);
+ rd_kafka_topic_partition_get_leader_epoch(rktpar),
+ (const char *)rktpar->metadata, rktpar->metadata_size, rktpar->err);
}

/**
18 changes: 18 additions & 0 deletions .builders/patches/librdkafka-fix-offsetfetch-null-cgrp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/src/rdkafka_request.c b/src/rdkafka_request.c
index d381016..7d38d20 100644
--- a/src/rdkafka_request.c
+++ b/src/rdkafka_request.c
@@ -1369,9 +1369,10 @@ err:

actions = rd_kafka_handle_OffsetFetch_err_action(rkb, err, request);

- if (actions & RD_KAFKA_ERR_ACTION_REFRESH) {
- /* Re-query for coordinator */
- rd_kafka_cgrp_op(rkb->rkb_rk->rk_cgrp, NULL, RD_KAFKA_NO_REPLYQ,
+ if ((actions & RD_KAFKA_ERR_ACTION_REFRESH) && rk->rk_cgrp) {
+ /* Re-query for coordinator only if this client has a consumer
+ * group. Admin requests may use clients without one. */
+ rd_kafka_cgrp_op(rk->rk_cgrp, NULL, RD_KAFKA_NO_REPLYQ,
RD_KAFKA_OP_COORD_QUERY, err);
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ sudo apt install -y --no-install-recommends build-essential libkrb5-dev libzstd-
LIBRDKAFKA_VERSION="v2.13.2"
LIBRDKAFKA_SHA256="14972092e4115f6e99f798a7cb420cbf6daa0c73502b3c52ae42fb5b418eea8f"
LIBRDKAFKA_TARBALL="${LIBRDKAFKA_VERSION}.tar.gz"
# Test against the same librdkafka the Agent ships: apply the PATCHES from .builders/images/linux-*/build_script.sh
LIBRDKAFKA_PATCHES_DIR="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)/.builders/patches"
LIBRDKAFKA_PATCHES="librdkafka-fix-coord-request-uaf.patch librdkafka-fix-offsetfetch-null-cgrp.patch"

wget "https://github.com/confluentinc/librdkafka/archive/refs/tags/${LIBRDKAFKA_TARBALL}"
echo "${LIBRDKAFKA_SHA256} ${LIBRDKAFKA_TARBALL}" | sha256sum -c -
tar -xzf "${LIBRDKAFKA_TARBALL}"
cd "librdkafka-${LIBRDKAFKA_VERSION#v}"
for patch in ${LIBRDKAFKA_PATCHES}; do
patch -p1 -i "${LIBRDKAFKA_PATCHES_DIR}/${patch}"
done
sudo ./configure --install-deps --prefix=/usr
make
sudo make install
Expand Down
12 changes: 6 additions & 6 deletions .deps/builder_inputs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
# Hash inputs are defined in .builders/inputs_hash.py (SHARED_INPUTS,
# RESOLUTION_INPUTS).
[resolution]
hash = "5d4d9b91dcf393e26f376fd9e6ab324834a9c7a70df8ff8629fab6693c99c857"
hash = "fb95e797fee428bee9469177e6bb8e3027ee2a106d76a45a05e27172a9a07596"

[images]
linux-aarch64 = "95d337dc72ff99d1bb64786b5df6dc15465a8d393b0d3ec330b8d01c14bdfab1"
linux-x86_64 = "197968e21d20e6f545c84561b420263e5e84b396d1e69d4121e165bc387fe4b3"
macos-aarch64 = "1041b5e91cc8b849d5f7777dae64d32950b82d2c51cc9c9e25ddb24dcc57b3f5"
macos-x86_64 = "e57d9ef3d13ed1b67b45c0f5b948705f21872abcf4919de9179137d4d0a25c3e"
windows-x86_64 = "34dbb1edda357bc22b36450e9afeecb37dd02a177e094c16182568b37808e4de"
linux-aarch64 = "6e1d909605fbf4ce37aaa03dd369c164eaa20f0105b719d775eef302336b826c"
linux-x86_64 = "d0f5d92c5ba466cd6d8d58d836d19bcf2773fa368b676400c70fa27ca3206ce3"
macos-aarch64 = "8dfce6c587ba6bf2f970cae2bd70b406e3165f98462cd376319f1c8e46c54eaa"
macos-x86_64 = "3b5023b444a9fef149b1b9862d3c0a662f33a2d37778117660f4606db026600a"
windows-x86_64 = "8ee7fd5f47bce769f750f4d2037c4f38ad560404b00abbfedb34484af40ae6e1"
6 changes: 3 additions & 3 deletions .deps/image_digests.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"linux-aarch64": "sha256:75788f20721ff5e7571a8abb29c625e59955bc0230749d7d50e34a6a73e3e856",
"linux-x86_64": "sha256:74df63142d8be4f9c7b14db454bf425b2217238619e815f42878220571910ea1",
"windows-x86_64": "sha256:6ac4bf21dd8c9ffa2856668c2a879b1ff3751032b91e27d33c7306c020808035"
"linux-aarch64": "sha256:3031cd4fb82c35169ec24964fbd01db4799fd86e09cbb468070c63c2c2448f0e",
"linux-x86_64": "sha256:4f922df29d7fedc247dbb876cde6094c56fb32c02407e14717c42e02aef87e66",
"windows-x86_64": "sha256:fe3f78454fd70d1533cd31ac37b2cef124d1c639081a067a01e109979b10b16d"
}
Loading
Loading