diff --git a/src/operator/attribute.rs b/src/operator/attribute.rs index 73e9c66..87ef7cb 100644 --- a/src/operator/attribute.rs +++ b/src/operator/attribute.rs @@ -197,9 +197,9 @@ impl FromOpAttr for String { where Self: Sized { - let mut out = vec![0_u8; len]; - ortsys![unsafe ReadOpAttr(attr, ort_sys::OrtOpAttrType::ORT_OP_ATTR_STRING, out.as_mut_ptr().cast(), len, &mut len)?]; - debug_assert_eq!(out.len(), len, "int attribute is smaller/larger than expected"); + let mut out = vec![0_u8; len + 1]; + ortsys![unsafe ReadOpAttr(attr, ort_sys::OrtOpAttrType::ORT_OP_ATTR_STRING, out.as_mut_ptr().cast(), len + 1, &mut len)?]; + debug_assert_eq!(out.len(), len + 1, "string attribute is smaller/larger than expected"); CString::from_vec_with_nul(out) .map_err(|_| Error::new("invalid string attribute contents")) .and_then(|f| f.into_string().map_err(|_| Error::new("invalid string attribute contents")))