tustvold commented on code in PR #3944:
URL: https://github.com/apache/arrow-rs/pull/3944#discussion_r1149124061


##########
arrow-schema/src/ffi.rs:
##########
@@ -152,6 +157,46 @@ impl FFI_ArrowSchema {
         Ok(self)
     }
 
+    pub fn with_metadata(
+        mut self,
+        metadata: Option<&HashMap<String, String>>,
+    ) -> Result<Self, ArrowError> {
+        let new_metadata = if let Some(metadata) = metadata {
+            if !metadata.is_empty() {
+                let mut metadata_serialized: Vec<u8> = Vec::new();
+                metadata_serialized.extend((metadata.len() as 
i32).to_ne_bytes());
+
+                for (key, value) in metadata.iter() {
+                    let key_len = key.len() as i32;
+                    let value_len = value.len() as i32;

Review Comment:
   Is it worth checking this doesn't overflow?



##########
arrow-schema/src/ffi.rs:
##########
@@ -152,6 +157,46 @@ impl FFI_ArrowSchema {
         Ok(self)
     }
 
+    pub fn with_metadata(
+        mut self,
+        metadata: Option<&HashMap<String, String>>,
+    ) -> Result<Self, ArrowError> {
+        let new_metadata = if let Some(metadata) = metadata {

Review Comment:
   ```suggestion
           // 
https://arrow.apache.org/docs/format/CDataInterface.html#c.ArrowSchema.metadata
           let new_metadata = if let Some(metadata) = metadata {
   ```



##########
arrow-schema/src/ffi.rs:
##########
@@ -212,6 +257,55 @@ impl FFI_ArrowSchema {
     pub fn dictionary_ordered(&self) -> bool {
         self.flags & 0b00000001 != 0
     }
+
+    pub fn metadata(&self) -> Result<HashMap<String, String>, ArrowError> {
+        if self.metadata.is_null() {
+            Ok(HashMap::new())
+        } else {
+            let mut pos = 0;
+            let buffer: *const u8 = self.metadata as *const u8;

Review Comment:
   Possibly not much we can do about this, but it occurs to me that this 
parsing code can very easily read into arbitrary memory



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to