Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CStr::from_bytes_until_nul to read rdkafka config #671

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chklauser
Copy link

@chklauser chklauser commented Apr 13, 2024

Commit 353812f replaced the more finicky CStr::from_bytes_with_nul with String::from_utf8_lossy. This causes tests to fail, both for me locally and in CI.

That commit eliminated a panic but now the returned Rust string (from NativeClientConfig.get) contains 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.

Commit 353812f 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.
@chklauser
Copy link
Author

353812f has not been released on crates.io as far as I can tell. => No need to add the bugfix to the changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant