Closed hwoithe closed 1 month ago
@JEnoch would you be able to take a look at this problem?
Hi @hwoithe, Thanks for reporting this!
You're right, in Zenoh Rust the Encoding's Suffix is always returned as a &str
which cannot be NULL.
So in our default cases the suffix is always an empty string:
z_get_options_default()
set the encoding to z_encoding_default()
z_encoding_default()
returns the conversion of Encoding::default()
which is actually the Empty
encoding value: Encoding::Exact(KnownEncoding::Empty)
. With this, Encoding.suffix()
returns a static empty stringI guess such empty string, even with a length of 0, is not a NULL pointer and therefore leads to safer behaviour than with suffix
set to z_bytes_t::empty()
.
We'll do a PR in zenoh-c to fix this.
Still, I think that in rmw_zenoh
the opts.value.encoding
could not changed, as it's already initialised by default to z_encoding_default()
corresponding to the Empty
encoding.
@Yadunund if you agree I'll just remove all the settings of encodings to z_encoding(Z_ENCODING_PREFIX_EMPTY, NULL);
(I count 4), as zenoh-c always initialises encoding in options with z_encoding_default()
.
As a side note, I didn't manage to reproduce the error, neither in Debug nor Release. But it probably depends on the memory alignment.
@JEnoch thanks for investigating the issue so quickly. The proposed approach sounds good to me.
I am unable to run service calls with a debug build. I am running commit
a8680fbcf51bded8c0612237150461dbe892a1b5
ofrmw_zenoh
. The build is compiled withcolcon build --cmake-args -DCMAKE_BUILD_TYPE=Debug
.terminal 1:
terminal 2:
terminal 3:
As we can see from the output above, the
from_raw_parts
call fails: https://github.com/eclipse-zenoh/zenoh-c/blob/390ec14e1b3785cd771bd6931db65062222bb735/src/get.rs#L308I believe this is because
val.encoding.suffix.start
is set to null when the encoding is created: https://github.com/ros2/rmw_zenoh/blob/a8680fbcf51bded8c0612237150461dbe892a1b5/rmw_zenoh_cpp/src/rmw_zenoh.cpp#L2279 https://github.com/eclipse-zenoh/zenoh-c/blob/390ec14e1b3785cd771bd6931db65062222bb735/src/commons.rs#L494 https://github.com/eclipse-zenoh/zenoh-c/blob/390ec14e1b3785cd771bd6931db65062222bb735/src/collections.rs#L35The
from_raw_parts
documentation indicates "data must be non-null": https://doc.rust-lang.org/beta/core/slice/fn.from_raw_parts.html#safetyIt would probably be best if
zenoh-c
does the right thing after checking ifval.encoding.suffix.start
is null, possibly by using an empty string if it is. I am not familiar enough with Zenoh to determine if this is a solution or ifrmw_zenoh
is creating the encoding in an unexpected way.I am using rustc 1.78.0 (9b00956e5 2024-04-29).