tustvold commented on code in PR #7096: URL: https://github.com/apache/arrow-rs/pull/7096#discussion_r1951714472
########## arrow-ipc/src/reader.rs: ########## @@ -2472,4 +2512,109 @@ mod tests { assert_eq!(decoded_batch.expect("Failed to read RecordBatch"), batch); }); } + + #[test] + fn test_validation_of_invalid_list_array() { + // ListArray with invalid offsets + let array = unsafe { + let values = Int32Array::from(vec![1, 2, 3]); + let bad_offsets = ScalarBuffer::<i32>::from(vec![0, 2, 4, 2]); // offsets can't go backwards + let offsets = OffsetBuffer::new_unchecked(bad_offsets); // INVALID array created + let field = Field::new_list_field(DataType::Int32, true); + let nulls = None; + ListArray::new(Arc::new(field), offsets, Arc::new(values), nulls) + }; + + expect_ipc_validation_error( + Arc::new(array), + "Invalid argument error: Offset invariant failure: offset at position 2 out of bounds: 4 > 2" + ); + } + + #[test] + fn test_validation_of_invalid_string_array() { + let valid: &[u8] = b" "; + let mut invalid = vec![]; + invalid.extend_from_slice(b"ThisStringIsCertainlyLongerThan12Bytes"); + invalid.extend_from_slice(INVALID_UTF8_FIRST_CHAR); + let binary_array = BinaryArray::from_iter(vec![None, Some(valid), None, Some(&invalid)]); + // data is not valid utf8 we can not construct a correct StringArray + // safely, so purposely create an invalid StringArray + let array = unsafe { + StringArray::new_unchecked( + binary_array.offsets().clone(), + binary_array.values().clone(), + binary_array.nulls().cloned(), + ) + }; + expect_ipc_validation_error( + Arc::new(array), + "Invalid argument error: Invalid UTF8 sequence at string index 3 (3..45): invalid utf-8 sequence of 1 bytes from index 38" Review Comment: This error message is a bit peculiar, but that's not really something for this PR -- 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