paleolimbot commented on code in PR #289:
URL: https://github.com/apache/arrow-nanoarrow/pull/289#discussion_r1306097887


##########
extensions/nanoarrow_ipc/src/nanoarrow/nanoarrow_ipc_reader_test.cc:
##########
@@ -291,6 +291,62 @@ TEST(NanoarrowIpcReader, StreamReaderExpectedSchema) {
   stream.release(&stream);
 }
 
+TEST(NanoarrowIpcTest, StreamReaderInvalidBuffer) {
+  struct ArrowBuffer input_buffer;
+  struct ArrowIpcInputStream input;
+  struct ArrowArrayStream stream;
+  struct ArrowSchema schema;
+  struct ArrowArray array;
+
+  uint8_t simple_stream_invalid[sizeof(kSimpleSchema) + 
sizeof(kSimpleRecordBatch)];
+  struct ArrowBufferView data;
+  data.data.as_uint8 = simple_stream_invalid;
+
+  // Create invalid data by removing bytes one at a time and ensuring an error 
code and
+  // a null-terminated error. After byte 273/280 this passes because the bytes 
are just
+  // padding.
+  data.size_bytes = sizeof(kSimpleSchema);
+  for (int64_t i = 1; i < 273; i++) {
+    memcpy(simple_stream_invalid, kSimpleSchema, i);
+    memcpy(simple_stream_invalid + i, kSimpleSchema + (i + 1),
+           (sizeof(kSimpleSchema) - i));
+
+    ArrowBufferInit(&input_buffer);
+    ASSERT_EQ(ArrowBufferAppendBufferView(&input_buffer, data), NANOARROW_OK);
+    ASSERT_EQ(ArrowIpcInputStreamInitBuffer(&input, &input_buffer), 
NANOARROW_OK);
+    ASSERT_EQ(ArrowIpcArrayStreamReaderInit(&stream, &input, nullptr), 
NANOARROW_OK);
+
+    ASSERT_NE(stream.get_schema(&stream, &schema), NANOARROW_OK)
+        << "After removing Schema message byte " << i;

Review Comment:
   Nice!
   
   ```
   
/Users/deweydunnington/Desktop/rscratch/arrow-nanoarrow/extensions/nanoarrow_ipc/src/nanoarrow/nanoarrow_ipc_reader_test.cc:345:
 Failure
   Expected: (stream.get_next(&stream, &array)) != (0), actual: 0 vs 0
   Google Test trace:
   
/Users/deweydunnington/Desktop/rscratch/arrow-nanoarrow/extensions/nanoarrow_ipc/src/nanoarrow/nanoarrow_ipc_reader_test.cc:332:
 144
   ```



-- 
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