-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-49079: [C++] Fix null pointer dereference in SimpleTable constructor #49086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
|
Hi @kou ,can you have a look at this ?? |
|
Can you add a test for this? |
|
I think that we must not accept If we want to check diff --git a/cpp/src/arrow/table.cc b/cpp/src/arrow/table.cc
index 68a8a1951f..2fd51d858e 100644
--- a/cpp/src/arrow/table.cc
+++ b/cpp/src/arrow/table.cc
@@ -260,12 +260,18 @@ std::vector<std::shared_ptr<Field>> Table::fields() const {
std::shared_ptr<Table> Table::Make(std::shared_ptr<Schema> schema,
std::vector<std::shared_ptr<ChunkedArray>> columns,
int64_t num_rows) {
+ if (std::any_of(columns.begin(), columns.end(), [](const auto& column) {return bool(column);})) {
+ return Status::Invalid(...);
+ }
return std::make_shared<SimpleTable>(std::move(schema), std::move(columns), num_rows);
}
std::shared_ptr<Table> Table::Make(std::shared_ptr<Schema> schema,
const std::vector<std::shared_ptr<Array>>& arrays,
int64_t num_rows) {
+ if (std::any_of(arrays.begin(), arrays.end(), [](const auto& array) {return bool(array);})) {
+ return Status::Invalid(...);
+ }
return std::make_shared<SimpleTable>(std::move(schema), arrays, num_rows);
} |
|
Hi @kou I have updated the PR to follow your suggestion. I've moved the validation to Table::Make using DCHECK to ensure that callers provide valid (non-null) arrays. I also reverted the change in the SimpleTable constructor to keep it consistent with the "no-nulls-accepted" policy. Additionally, I've included a fix for the macOS CI failures caused by the missing pkg-config@0.29.2 formula in Homebrew. |
|
Why did you use
Could you work on it as a separated task (open a separated issue and PR) instead of mixing this PR? It's not related to this issue. |
|
Hi @kou, Thank you for the feedback! Regarding I have also replaced the Regarding the macOS CI fix: Please let me know if there are any other areas that need adjustments. Thanks again! |
095d1ec to
6188125
Compare
|
Hi @WillAyd, I've added the requested tests in Specifically, I added:
|
Rationale for This Change
The
SimpleTableconstructor incpp/src/arrow/table.cccan crash if the first column provided isnull. This happens because the constructor attempts to dereferencecolumns[0]to determine the row count before performing any validation.This change ensures safe initialization when columns are empty or the first column is null.
What Changes Are Included in This PR?
A null-pointer safety check has been added to both
SimpleTableconstructors to prevent dereferencing a null column during initialization:Are These Changes Tested?
Yes. The change has been verified using the existing unit test suite.
Are There Any User-Facing Changes?
No. This change only improves internal safety and does not affect public APIs or user-visible behavior.