viirya commented on code in PR #8097:
URL: https://github.com/apache/arrow-rs/pull/8097#discussion_r2263646158


##########
arrow-ipc/src/reader.rs:
##########
@@ -1740,6 +1753,40 @@ mod tests {
         .unwrap()
     }
 
+    #[test]
+    fn test_negative_meta_len_start_stream() {
+        let bytes = i32::to_le_bytes(-1);
+        let mut buf = vec![];
+        buf.extend(CONTINUATION_MARKER);
+        buf.extend(bytes);
+
+        let reader = StreamReader::try_new(Cursor::new(buf), None);
+        assert!(reader.is_err());
+    }
+
+    #[test]
+    fn test_negative_meta_len_mid_stream() {
+        let schema = Schema::new(vec![Field::new("a", DataType::Int32, 
false)]);
+        let mut buf = Vec::new();
+        {
+            let mut writer = crate::writer::StreamWriter::try_new(&mut buf, 
&schema).unwrap();
+            let batch =
+                RecordBatch::try_new(Arc::new(schema), 
vec![Arc::new(Int32Array::from(vec![1]))])
+                    .unwrap();
+            writer.write(&batch).unwrap();
+        }
+
+        let bytes = i32::to_le_bytes(-1);
+        buf.extend(CONTINUATION_MARKER);
+        buf.extend(bytes);
+
+        let mut reader = StreamReader::try_new(Cursor::new(buf), 
None).unwrap();
+        // Read the valid value
+        assert!(reader.maybe_next().is_ok());
+        // Read the invalid meta len
+        assert!(reader.maybe_next().is_err());

Review Comment:
   ```suggestion
           let batch_err = reader.maybe_next().err();
           assert!(batch_err.is_some());
           assert_eq!(
               batch_err.unwrap().to_string(),
               "Parser error: Invalid metadata length: -1"
           );
   ```



-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to