This is an automated email from the ASF dual-hosted git repository.
Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new dc6750741c Don't panic on invalid c ffi schema name (#10328)
dc6750741c is described below
commit dc6750741c5347010c9530dbf61cb77c09239d82
Author: Robert Kruszewski <[email protected]>
AuthorDate: Tue Jul 14 11:51:44 2026 +0100
Don't panic on invalid c ffi schema name (#10328)
# Which issue does this PR close?
mailing list thread "Spec clarification on field names"
https://lists.apache.org/thread/v2fvqjtfrvsrbm133yc7yjrxvjh0x3l5
# Rationale for this change
Arrow supports names that are not valid c string names. Instead of
having the caller validate themselves the ArrowSchema C FFI already
validates on the rust side, instead of panicing propagate the error to
the user
# What changes are included in this PR?
Propagate Cstring::new error to the user instead of panicing
# Are these changes tested?
Added tests
# Are there any user-facing changes?
Error instead of panic
---------
Signed-off-by: Robert Kruszewski <[email protected]>
---
arrow-schema/src/ffi.rs | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/arrow-schema/src/ffi.rs b/arrow-schema/src/ffi.rs
index 435526f188..f2cfaea026 100644
--- a/arrow-schema/src/ffi.rs
+++ b/arrow-schema/src/ffi.rs
@@ -171,7 +171,14 @@ impl FFI_ArrowSchema {
/// Set the name of the schema
pub fn with_name(mut self, name: &str) -> Result<Self, ArrowError> {
- self.name = CString::new(name).unwrap().into_raw();
+ self.name = CString::new(name)
+ .map_err(|e| {
+ ArrowError::CDataInterface(format!(
+ "Null byte at position {} not allowed in name",
+ e.nul_position()
+ ))
+ })?
+ .into_raw();
Ok(self)
}
@@ -1008,6 +1015,12 @@ mod tests {
}
}
+ #[test]
+ fn test_name_with_null_byte() {
+ let schema = FFI_ArrowSchema::try_new("i", vec![], None).unwrap();
+ assert!(schema.with_name("ab\0cd").is_err());
+ }
+
#[test]
fn test_import_field_with_null_name() {
let dtype = DataType::Int16;