This is an automated email from the ASF dual-hosted git repository.
bkietz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new ec91a50 ARROW-12837: [C++] Do not crash when printing invalid arrays
ec91a50 is described below
commit ec91a50897efe163e7edcc0ec191b84a260c9f47
Author: Alessandro Molina <[email protected]>
AuthorDate: Tue Jul 27 07:44:58 2021 -0400
ARROW-12837: [C++] Do not crash when printing invalid arrays
Closes #10713 from amol-/ARROW-12837
Authored-by: Alessandro Molina <[email protected]>
Signed-off-by: Benjamin Kietzman <[email protected]>
---
cpp/src/arrow/array/array_test.cc | 8 ++++++++
cpp/src/arrow/pretty_print.cc | 6 ++++++
2 files changed, 14 insertions(+)
diff --git a/cpp/src/arrow/array/array_test.cc
b/cpp/src/arrow/array/array_test.cc
index 7b10acb..baa1c54 100644
--- a/cpp/src/arrow/array/array_test.cc
+++ b/cpp/src/arrow/array/array_test.cc
@@ -111,6 +111,14 @@ TEST_F(TestArray, TestLength) {
ASSERT_EQ(arr->length(), 100);
}
+TEST_F(TestArray, TestNullToString) {
+ // Invalid NULL buffer
+ auto data = std::make_shared<Buffer>(nullptr, 400);
+
+ std::unique_ptr<Int32Array> arr(new Int32Array(100, data));
+ ASSERT_EQ(arr->ToString(), "<InvalidArray: Missing values buffer in
non-empty array>");
+}
+
TEST_F(TestArray, TestSliceSafe) {
std::vector<int32_t> original_data{1, 2, 3, 4, 5, 6, 7};
auto arr = std::make_shared<Int32Array>(7, Buffer::Wrap(original_data));
diff --git a/cpp/src/arrow/pretty_print.cc b/cpp/src/arrow/pretty_print.cc
index 8d1c16e..60cdaf0 100644
--- a/cpp/src/arrow/pretty_print.cc
+++ b/cpp/src/arrow/pretty_print.cc
@@ -325,6 +325,12 @@ class ArrayPrinter : public PrettyPrinter {
std::is_base_of<FixedSizeListArray, T>::value,
Status>
Visit(const T& array) {
+ Status st = array.Validate();
+ if (!st.ok()) {
+ (*sink_) << "<InvalidArray: " << st.message() << ">";
+ return Status::OK();
+ }
+
OpenArray(array);
if (array.length() > 0) {
RETURN_NOT_OK(WriteDataValues(array));