Skip to content

Commit 7e0e982

Browse files
committed
apacheGH-54936: [C++] Ensure reading an invalid map array from IPC doesn't crash
1 parent 9630caa commit 7e0e982

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎cpp/src/arrow/ipc/reader.cc‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <flatbuffers/flatbuffers.h> // IWYU pragma: export
3535

3636
#include "arrow/array.h"
37+
#include "arrow/array/validate.h"
3738
#include "arrow/buffer.h"
3839
#include "arrow/extension_type.h"
3940
#include "arrow/io/caching.h"
@@ -455,6 +456,21 @@ class ArrayLoader {
455456

456457
Status Visit(const MapType& type) {
457458
RETURN_NOT_OK(LoadList(type));
459+
if (!out_->child_data.empty()) {
460+
// Ensure that GetNullCount() calls in MapArray::ValidateChildData
461+
// don't access invalid memory.
462+
// We cannot call array validation as it will fail on non-native endianness
463+
// (due to checking the last offset on variable-width data) or missing
464+
// dictionaries (they are not yet populated at this point).
465+
const ArrayData& child_data = *out_->child_data[0];
466+
if (child_data.null_count != 0) {
467+
return Status::Invalid("Map array child array should have no nulls");
468+
}
469+
if (!child_data.child_data.empty() && child_data.child_data[0]->null_count != 0) {
470+
return Status::Invalid("Map array keys array should have no nulls");
471+
}
472+
}
473+
// If we don't do this, MapArray::SetData will abort on invalid data.
458474
return MapArray::ValidateChildData(out_->child_data);
459475
}
460476

0 commit comments

Comments
 (0)