diff --git a/core-foundation/src/data.rs b/core-foundation/src/data.rs index 9f95219..b799ed3 100644 --- a/core-foundation/src/data.rs +++ b/core-foundation/src/data.rs @@ -81,7 +81,14 @@ impl CFData { /// read-only. #[inline] pub fn bytes(&self) -> &[u8] { - unsafe { slice::from_raw_parts(CFDataGetBytePtr(self.0), self.len() as usize) } + unsafe { + let ptr = CFDataGetBytePtr(self.0); + // Rust slice must never have a NULL pointer + if ptr.is_null() { + return &[]; + } + slice::from_raw_parts(ptr, self.len() as usize) + } } /// Returns the length of this byte buffer.