From 8c266191983c86040fef10da657fcff873c1c1d9 Mon Sep 17 00:00:00 2001 From: Christian Klauser Date: Sun, 16 Jun 2024 12:06:48 +0200 Subject: [PATCH 1/2] Bump MSRV to 1.69 We want to use `CStr::from_bytes_until_nul` for reading values from rdkafka. --- .github/workflows/ci.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- changelog.md | 2 ++ rdkafka-sys/Cargo.toml | 2 +- src/lib.rs | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96708961d..06df67deb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: branches: [master] env: - rust_version: 1.61.0 + rust_version: 1.69.0 jobs: lint: diff --git a/Cargo.toml b/Cargo.toml index e190bd18e..064c7ec08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["kafka", "rdkafka"] categories = ["api-bindings"] edition = "2018" exclude = ["Cargo.lock"] -rust-version = "1.61" +rust-version = "1.69" [workspace] members = ["rdkafka-sys"] diff --git a/README.md b/README.md index 6070ef6a7..cb44723f3 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ re-exported as rdkafka features. ### Minimum supported Rust version (MSRV) -The current minimum supported Rust version (MSRV) is 1.61.0. Note that +The current minimum supported Rust version (MSRV) is 1.69.0. Note that bumping the MSRV is not considered a breaking change. Any release of rust-rdkafka may bump the MSRV. diff --git a/changelog.md b/changelog.md index 1806d5807..c9610a36b 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,8 @@ See also the [rdkafka-sys changelog](rdkafka-sys/changelog.md). ## Unreleased +* Bump MSRV to 1.69 + ## 0.36.2 (2024-01-16) * Update `BaseConsumer::poll` to return `None` when handling rebalance diff --git a/rdkafka-sys/Cargo.toml b/rdkafka-sys/Cargo.toml index 4870e15b3..ea937216e 100644 --- a/rdkafka-sys/Cargo.toml +++ b/rdkafka-sys/Cargo.toml @@ -10,7 +10,7 @@ description = "Native bindings to the librdkafka library" keywords = ["kafka", "rdkafka"] categories = ["external-ffi-bindings"] edition = "2018" -rust-version = "1.61" +rust-version = "1.69" [dependencies] num_enum = "0.5.0" diff --git a/src/lib.rs b/src/lib.rs index 79a8d113f..8854adc92 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -176,7 +176,7 @@ //! //! ### Minimum supported Rust version (MSRV) //! -//! The current minimum supported Rust version (MSRV) is 1.61.0. Note that +//! The current minimum supported Rust version (MSRV) is 1.69.0. Note that //! bumping the MSRV is not considered a breaking change. Any release of //! rust-rdkafka may bump the MSRV. //! From fc8d46bc9dbf648d8d2cdb0ce583dce2dce420c0 Mon Sep 17 00:00:00 2001 From: Christian Klauser Date: Sat, 13 Apr 2024 16:11:24 +0200 Subject: [PATCH 2/2] Use CStr::from_bytes_until_nul to read rdkafka config Commit 353812ff958b4b65f9e65dd22a60e770ed6ba948 replaced the more finicky `CStr::from_bytes_with_nul` with `String::from_utf8_lossy`. That eliminated a panic but the returned Rust string now contained NUL bytes. This might have accidentally worked in FFI APIs that take C strings, but it fails when such a string is passed to a Rust API, such as integer parsing in `stream_consumer.rs:217`. The newer `CStr::from_bytes_until_nul` function 1. does not panic 2. ends the string at the first NUL byte It does return an error when there is no NUL byte in the input slice. While it would be possible to fall back to `String::from_utf8_lossy` in that case, I'm not sure that would be a good idea. If we are in that situation, librdkafka clearly has messed something up completely. The contents of the buffer are then more likely complete garbage. --- src/config.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 296d9f867..29a83863c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -150,7 +150,10 @@ impl NativeClientConfig { } // Convert the C string to a Rust string. - Ok(String::from_utf8_lossy(&buf).to_string()) + Ok(CStr::from_bytes_until_nul(&buf) + .expect("rd_kafka_conf_get to write a NUL-terminated string.") + .to_string_lossy() + .to_string()) } }